From 18d3376c99c36630a099c41a87b9e3da59ed84c9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:14:39 +0000 Subject: [PATCH] ci: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/sk_transformers/generic_transformer.py | 8 +++--- src/sk_transformers/string_transformer.py | 30 ++++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/sk_transformers/generic_transformer.py b/src/sk_transformers/generic_transformer.py index c145d45..e882950 100644 --- a/src/sk_transformers/generic_transformer.py +++ b/src/sk_transformers/generic_transformer.py @@ -291,9 +291,11 @@ def transform(self, X: pd.DataFrame) -> pd.DataFrame: agg_df = X.groupby(groupby_columns).agg( [ - getattr(pl, agg_func)(agg_column).alias(agg_new_column) - if isinstance(agg_func, str) - else pl.col(agg_column).apply(agg_func).alias(agg_new_column) + ( + getattr(pl, agg_func)(agg_column).alias(agg_new_column) + if isinstance(agg_func, str) + else pl.col(agg_column).apply(agg_func).alias(agg_new_column) + ) for (agg_column, agg_func, agg_new_column) in agg_features ] ) diff --git a/src/sk_transformers/string_transformer.py b/src/sk_transformers/string_transformer.py index d7bb218..22e064e 100644 --- a/src/sk_transformers/string_transformer.py +++ b/src/sk_transformers/string_transformer.py @@ -489,9 +489,11 @@ def __init__( ) -> None: super().__init__() self.features = [ - (split_tuple[0], split_tuple[1], split_tuple[2]) - if len(split_tuple) == 3 - else (split_tuple[0], split_tuple[1], -1) + ( + (split_tuple[0], split_tuple[1], split_tuple[2]) + if len(split_tuple) == 3 + else (split_tuple[0], split_tuple[1], -1) + ) for split_tuple in features ] @@ -515,20 +517,22 @@ def transform(self, X: pd.DataFrame) -> pd.DataFrame: ] select_with_expr = [ - pl.col(column) - .str.splitn(by=separator, n=max_possible_split + 1) - .struct.rename_fields( - [column + f"_part_{i}" for i in range(1, max_possible_split + 2)] - ) - .alias(column + "_alias") - if maxsplit in [0, -1] or maxsplit > max_possible_split - else ( + ( pl.col(column) - .str.splitn(by=separator, n=maxsplit + 1) + .str.splitn(by=separator, n=max_possible_split + 1) .struct.rename_fields( - [column + f"_part_{i}" for i in range(1, maxsplit + 2)] + [column + f"_part_{i}" for i in range(1, max_possible_split + 2)] ) .alias(column + "_alias") + if maxsplit in [0, -1] or maxsplit > max_possible_split + else ( + pl.col(column) + .str.splitn(by=separator, n=maxsplit + 1) + .struct.rename_fields( + [column + f"_part_{i}" for i in range(1, maxsplit + 2)] + ) + .alias(column + "_alias") + ) ) for (column, separator, maxsplit), max_possible_split in zip( self.features, max_possible_splits_list