-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: Adding skipna as an option to groupby cumsum and cumprod #19914
Changes from 6 commits
90b7978
84db344
6182352
2579eaa
75d2870
bb740fd
47fe8d6
107bc0b
5aceda9
3072df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2521,6 +2521,34 @@ def test_groupby_cumprod(self): | |
expected.name = 'value' | ||
tm.assert_series_equal(actual, expected) | ||
|
||
def test_groupby_cum_skipna(self): | ||
# GH 19806 | ||
# make sure that skipna works for both cumsum and cumprod | ||
df = pd.DataFrame({'key': ['b'] * 10 + ['a'] * 2, 'value': 3}) | ||
df.at[3] = np.nan | ||
df.at[3, 'key'] = 'b' | ||
|
||
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. ideally you could parameterize this over skipna=True/False 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. I parametrized it over cumprod/sum & skipna. |
||
result = df.groupby('key')['value'].cumprod(skipna=False) | ||
expected = pd.Series([3.0, 9.0, 27.0, np.nan, np.nan, np.nan, np.nan, | ||
np.nan, np.nan, np.nan, 3.0, 9.0], | ||
name='value', index=range(12)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
result = df.groupby('key')['value'].cumsum(skipna=False) | ||
expected = pd.Series([3.0, 6.0, 9.0, np.nan, np.nan, np.nan, np.nan, | ||
np.nan, np.nan, np.nan, 3.0, 6.0], | ||
name='value', index=range(12)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
df = pd.DataFrame({'key': ['b'] * 10, 'value': np.nan}) | ||
result = df.groupby('key')['value'].cumprod(skipna=False) | ||
expected = pd.Series([np.nan] * 10, name='value', index=range(10)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
result = df.groupby('key')['value'].cumsum(skipna=False) | ||
expected = pd.Series([np.nan] * 10, name='value', index=range(10)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
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. Could you add a test for 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. That should be covered by |
||
def test_ops_general(self): | ||
ops = [('mean', np.mean), | ||
('median', np.median), | ||
|
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.
this needs to go with the other cumsum tests in pandas/tests/groupby/test_transform.py. put near the other cum* tests.
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.
Ok, I moved it to test_transform.py