Closes #5406: Series accessor groupby #5407
Merged
+72
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a
groupby()method to theArkoudaSeriesAccessor,enabling pandas-style grouping directly from an Arkouda-backed
pd.Series:This eliminates the need for users to access internal
_dataattributesand provides a clean, abstraction-safe API.
Motivation
Previously, users had to write:
Accessing
._databreaks encapsulation and bypasses the ExtensionArrayabstraction layer.
This PR introduces:
which: - Preserves the pandas accessor pattern - Avoids NumPy
materialization - Returns a proper
arkouda.pandas.groupbyclass.GroupByobject - Maintains zero-copy behavior
Implementation Details
Changes
arkouda/pandas/extension/_series_accessor.pyGroupByfromarkouda.pandas.groupbyclassgroupby(self) -> GroupBymethod toArkoudaSeriesAccessor_data)GroupBy(akcol)The method raises:
TypeErrorif the Series is not Arkouda-backedTypeErrorif the underlying_dataattribute is missingThis ensures correctness and defensive behavior.
Tests
Added tests under:
Coverage includes:
ak.GroupByg.size()matches pandasvalue_counts().sort_index()_datais unavailableThis validates both happy-path and failure cases.
API Behavior
Example
Equivalent to:
But without leaking internal implementation details.
Design Notes
Future Extensions (Optional)
This lays the groundwork for:
g.sum()g.min()/g.max()Closes #5406: Series accessor groupby