From 55765d811ebeb5a3dd017eac631e4dfd460ad3d5 Mon Sep 17 00:00:00 2001 From: Doug Branton Date: Fri, 26 Jul 2024 14:18:40 -0700 Subject: [PATCH 1/3] add rename fix --- src/nested_pandas/utils/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nested_pandas/utils/utils.py b/src/nested_pandas/utils/utils.py index 0f980d2..9c9ea88 100644 --- a/src/nested_pandas/utils/utils.py +++ b/src/nested_pandas/utils/utils.py @@ -30,8 +30,9 @@ def count_nested(df, nested, by=None, join=True) -> NestedFrame: if by is None: field_to_len = df[nested].nest.fields[0] counts = ( - df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1).rename(f"n_{nested}") + df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1) # .rename(f"n_{nested}") ) + counts.name = f"n_{nested}" # update name directly (rename causes issues downstream) else: # this may be able to be sped up using tolists() as well counts = df[nested].apply(lambda x: x[by].value_counts(sort=False)) From e6ddb469fa360f2cfaba64aca783b8df6dbc7feb Mon Sep 17 00:00:00 2001 From: Doug Branton Date: Fri, 26 Jul 2024 14:21:11 -0700 Subject: [PATCH 2/3] add rename fix --- src/nested_pandas/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nested_pandas/utils/utils.py b/src/nested_pandas/utils/utils.py index 9c9ea88..ea17ce1 100644 --- a/src/nested_pandas/utils/utils.py +++ b/src/nested_pandas/utils/utils.py @@ -30,7 +30,7 @@ def count_nested(df, nested, by=None, join=True) -> NestedFrame: if by is None: field_to_len = df[nested].nest.fields[0] counts = ( - df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1) # .rename(f"n_{nested}") + df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1) ) counts.name = f"n_{nested}" # update name directly (rename causes issues downstream) else: From b8bcf1c46232c5836432fad924ad638a367231c3 Mon Sep 17 00:00:00 2001 From: Doug Branton Date: Fri, 26 Jul 2024 14:27:14 -0700 Subject: [PATCH 3/3] formatting --- src/nested_pandas/utils/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/nested_pandas/utils/utils.py b/src/nested_pandas/utils/utils.py index ea17ce1..e337dcf 100644 --- a/src/nested_pandas/utils/utils.py +++ b/src/nested_pandas/utils/utils.py @@ -29,9 +29,7 @@ def count_nested(df, nested, by=None, join=True) -> NestedFrame: if by is None: field_to_len = df[nested].nest.fields[0] - counts = ( - df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1) - ) + counts = df[nested].nest.to_lists().apply(lambda x: len(x[field_to_len]), axis=1) counts.name = f"n_{nested}" # update name directly (rename causes issues downstream) else: # this may be able to be sped up using tolists() as well