-
-
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
Merged
mroeschke
merged 18 commits into
pandas-dev:main
from
bdwzhangumich:accumulate_categorical
Apr 23, 2024
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fa74733
Added tests with and without np.nan
xiangchris 269dcfb
Added tests for cummin and cummax
xiangchris a8a1f37
Merge branch 'accumulate_categorical' of github.com:bdwzhangumich/pan…
xiangchris 9ec47bf
Fixed series tests expected series, rewrote categorical arrays to use…
xiangchris c224faf
Fixed cat not defined error and misspelling
xiangchris 330b60d
Implement _accumulate for Categorical
bdwzhangumich e927cda
Merge branch 'pandas-dev:main' into accumulate_categorical
bdwzhangumich 0122334
fixed misspellings in tests
xiangchris 4caea9f
Merge branch 'accumulate_categorical' of github.com:bdwzhangumich/pan…
xiangchris 098ad64
fixed expected categories on tests
xiangchris 126bc19
Updated whatsnew
bdwzhangumich 498ad6d
Merge branch 'pandas-dev:main' into accumulate_categorical
bdwzhangumich 18a86e2
Update doc/source/whatsnew/v3.0.0.rst
bdwzhangumich 5c5ac3c
Removed testing for _accumulate.
xiangchris 7934f74
Merge branch 'accumulate_categorical' of github.com:bdwzhangumich/pan…
xiangchris 1abad3e
Moved categorical_accumulations.py logic to categorical.py
bdwzhangumich 6be5f8c
Merge branch 'main' into accumulate_categorical
xiangchris babc835
Assigned expected results to expected variable; Added pytest.mark.par…
xiangchris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,6 +170,53 @@ def test_cummethods_bool_in_object_dtype(self, method, expected): | |
result = getattr(ser, method)() | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"method, order", | ||
[ | ||
["cummax", "abc"], | ||
["cummin", "cba"], | ||
], | ||
) | ||
def test_cummax_cummin_on_ordered_categorical(self, method, order): | ||
# GH#52335 | ||
cat = pd.CategoricalDtype(list(order), ordered=True) | ||
ser = pd.Series( | ||
list("ababcab"), dtype=pd.CategoricalDtype(list(order), ordered=True) | ||
) | ||
result = getattr(ser, method)() | ||
tm.assert_series_equal(result, pd.Series(list("abbbccc"), dtype=cat)) | ||
|
||
@pytest.mark.parametrize( | ||
"method, order", | ||
[ | ||
["cummax", "abc"], | ||
["cummin", "cba"], | ||
], | ||
) | ||
def test_cummax_cummin_ordered_categorical_nan(self, method, order): | ||
# GH#52335 | ||
ser = pd.Series( | ||
["a", np.nan, "b", "a", "c"], | ||
dtype=pd.CategoricalDtype(list(order), ordered=True), | ||
) | ||
result = getattr(ser, method)(skipna=True) | ||
tm.assert_series_equal( | ||
result, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can you assign this to an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assigned all expected series to |
||
), | ||
) | ||
|
||
result = getattr(ser, method)(skipna=False) | ||
tm.assert_series_equal( | ||
result, | ||
pd.Series( | ||
["a", np.nan, np.nan, np.nan, np.nan], | ||
dtype=pd.CategoricalDtype(list(order), ordered=True), | ||
), | ||
) | ||
|
||
def test_cumprod_timedelta(self): | ||
# GH#48111 | ||
ser = pd.Series([pd.Timedelta(days=1), pd.Timedelta(days=3)]) | ||
|
Oops, something went wrong.
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.
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
withskipna=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
totest_cummax_cummin_ordered_categorical_nan
withskipna
and expected data