Skip to content

Commit

Permalink
Fix handling of others_df in top_n function to ensure proper naming f…
Browse files Browse the repository at this point in the history
…or Series and DataFrame types
  • Loading branch information
andrewbolster committed Jan 6, 2025
1 parent 88dc444 commit 57582e9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bolster/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,8 @@ def top_n(df: pd.DataFrame,

top_df = df.iloc[:n]
others_df = df.iloc[n:].sum(numeric_only=True)
others_df.name = others
if isinstance(others_df, (pd.Series, pd.DataFrame)):
others_df.name = others
else:
others_df = pd.Series(others_df,name=others)
return pd.concat([top_df, others_df.to_frame().T])

0 comments on commit 57582e9

Please sign in to comment.