-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Implement cummax and cummin in _accumulate() for ordered Categorical arrays #58360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Implement cummax and cummin in _accumulate() for ordered Categorical arrays #58360
Conversation
…das-brandon into accumulate_categorical
…das-brandon into accumulate_categorical
import numpy as np | ||
|
||
|
||
def _cum_func( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just include all this logic in pandas/core/arrays/categorical.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the logic into pandas/core/arrays/categorical.py
Co-authored-by: Matthew Roeschke <[email protected]>
…das-brandon into accumulate_categorical
["a", np.nan, "b", "a", "c"], | ||
dtype=pd.CategoricalDtype(list(order), ordered=True), | ||
) | ||
result = getattr(ser, method)(skipna=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use pytest.mark.parametrize
with skipna=True|False
and the expected result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a pytest.mark.parametrize
to test_cummax_cummin_ordered_categorical_nan
with skipna
and expected data
pd.Series( | ||
["a", np.nan, "b", "b", "c"], | ||
dtype=pd.CategoricalDtype(list(order), ordered=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you assign this to an expected
variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigned all expected series to expected
variables
…ametrize to test_cummax_cummin_ordered_categorical_nan with skipna and expected data
Thanks @bdwzhangumich |
…ical arrays (pandas-dev#58360) * Added tests with and without np.nan * Added tests for cummin and cummax * Fixed series tests expected series, rewrote categorical arrays to use pd.Categorical * Fixed cat not defined error and misspelling * Implement _accumulate for Categorical * fixed misspellings in tests * fixed expected categories on tests * Updated whatsnew * Update doc/source/whatsnew/v3.0.0.rst Co-authored-by: Matthew Roeschke <[email protected]> * Removed testing for _accumulate. * Moved categorical_accumulations.py logic to categorical.py * Assigned expected results to expected variable; Added pytest.mark.parametrize to test_cummax_cummin_ordered_categorical_nan with skipna and expected data --------- Co-authored-by: Christopher Xiang <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]> Co-authored-by: Chris Xiang <[email protected]>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.We implemented the operations cummax and cummin in the _accumulate() function for the Categorical array class. The implementation includes a check that the Categorical array is ordered and is based on other implementations of _accumulate(). Tests for the implementation have also been written and included.
Coauthored with @xiangchris