Skip to content

Commit 6a2ac30

Browse files
author
niklasmueboe
committed
drop empty categories
1 parent 0de58dd commit 6a2ac30

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ovrlpy/io.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
def _filter_genes(df: pl.DataFrame, remove_features: Collection[str]) -> pl.DataFrame:
99
if len(remove_features) > 0:
10-
df = df.filter(
11-
~pl.col("gene").cast(pl.Utf8).str.contains(f"({'|'.join(remove_features)})")
10+
remove_pattern = "|".join(remove_features)
11+
df = (
12+
df.lazy()
13+
.with_columns(pl.col("gene").cast(pl.String))
14+
.filter(~pl.col("gene").str.contains(f"({remove_pattern})"))
15+
.with_columns(pl.col("gene").cast(pl.Categorical))
16+
.collect()
1217
)
1318
return df
1419

0 commit comments

Comments
 (0)