Skip to content

Commit

Permalink
Merge pull request #127 from lincc-frameworks/fix-rename-bug
Browse files Browse the repository at this point in the history
count_nested: Update series name directly
  • Loading branch information
dougbrn authored Jul 26, 2024
2 parents bc85088 + b8bcf1c commit 71ae3ba
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/nested_pandas/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ 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}")
)
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
counts = df[nested].apply(lambda x: x[by].value_counts(sort=False))
Expand Down

0 comments on commit 71ae3ba

Please sign in to comment.