-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Adding skipna as an option to groupby cumsum and cumprod #19914
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
Changes from 1 commit
90b7978
84db344
6182352
2579eaa
75d2870
bb740fd
47fe8d6
107bc0b
5aceda9
3072df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2523,16 +2523,22 @@ def test_groupby_cumprod(self): | |
|
||
# make sure that skipna works | ||
df = pd.concat( | ||
[pd.DataFrame({'x': [1.0, 2.0, np.nan, np.nan, 3.0, 2.0], 'gp': 'a'}), | ||
pd.DataFrame({'x': [2.0, 5.0, 6.0, 1.0, np.nan, 1.0], 'gp': 'b'})]) | ||
[pd.DataFrame({'x': [1.0, 2.0, np.nan, np.nan, 3.0, 2.0], | ||
'gp': 'a'}), | ||
pd.DataFrame({'x': [2.0, 5.0, 6.0, 1.0, np.nan, 1.0], | ||
'gp': 'b'})]) | ||
result = df.groupby('gp')['x'].cumprod(skipna=False) | ||
expected = pd.Series([1.0, 2.0, np.nan, np.nan, np.nan, np.nan, 2.0, 10.0, 60.0, 60.0, np.nan, np.nan], | ||
name='x', index=(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5)) | ||
expected = pd.Series([1.0, 2.0, np.nan, np.nan, np.nan, np.nan, | ||
2.0, 10.0, 60.0, 60.0, np.nan, np.nan], | ||
name='x', index=(0, 1, 2, 3, 4, 5, | ||
0, 1, 2, 3, 4, 5)) | ||
tm.assert_series_equal(result, expected) | ||
|
||
result = df.groupby('gp')['x'].cumprod() | ||
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. Don't think you need this test. 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. Yep, removed it. |
||
expected = pd.Series([1.0, 2.0, np.nan, np.nan, 6.0, 12.0, 2.0, 10.0, 60.0, 60.0, np.nan, 60.0], | ||
name='x', index=(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5)) | ||
expected = pd.Series([1.0, 2.0, np.nan, np.nan, 6.0, 12.0, | ||
2.0, 10.0, 60.0, 60.0, np.nan, 60.0], | ||
name='x', index=(0, 1, 2, 3, 4, 5, | ||
0, 1, 2, 3, 4, 5)) | ||
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): | ||
|
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 split this into a new test? Make sure to add a reference to the Github issue as a comment.
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'd find this a bit easier to read as
instead of
concat
.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.
And maybe have a group with all-NA to ensure that is handled properly.
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 added a new test (
test_groupby_cum_skipna
) for all of the skipna-related cases. And added a groupby+cumsum/prod on all-NA values.