-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
... #25315
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
... #25315
Changes from all commits
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 |
---|---|---|
|
@@ -1171,10 +1171,18 @@ def std(self, ddof=1, *args, **kwargs): | |
ddof : integer, default 1 | ||
degrees of freedom | ||
""" | ||
|
||
# TODO: implement at Cython level? | ||
nv.validate_groupby_func('std', args, kwargs) | ||
return np.sqrt(self.var(ddof=ddof, **kwargs)) | ||
if ddof == 1: | ||
try: | ||
return self._cython_agg_general('std', **kwargs) | ||
except Exception: | ||
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. Not entirely clear what this is for but except for legacy code we never catch just base Exception so will need something more explicit 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. Copy / paste isn't the right way to go here. Can you still keep the dispatch to |
||
f = lambda x: x.std(ddof=ddof, **kwargs) | ||
with _group_selection_context(self): | ||
return self._python_agg_general(f) | ||
else: | ||
f = lambda x: x.std(ddof=ddof, **kwargs) | ||
with _group_selection_context(self): | ||
return self._python_agg_general(f) | ||
|
||
@Substitution(name='groupby') | ||
@Appender(_common_see_also) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1698,3 +1698,35 @@ def test_groupby_agg_ohlc_non_first(): | |
result = df.groupby(pd.Grouper(freq='D')).agg(['sum', 'ohlc']) | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_groupby_std_with_as_index_false(): | ||
# https://github.com/pandas-dev/pandas/issues/16799 | ||
|
||
df = pd.DataFrame({ | ||
"A": ["a", "b", "a", "b"], | ||
"B": ["A", "B", "A", "B"], | ||
"X": [1, 2, 3, 4] | ||
}) | ||
|
||
group_var = df.groupby( | ||
["A", "B"], | ||
as_index=False, | ||
).var() | ||
|
||
# A B X | ||
# 0 a A 2 | ||
# 1 b B 2 | ||
|
||
group_std = df.groupby( | ||
["A", "B"], | ||
as_index=False, | ||
).std() | ||
|
||
# A B X | ||
# 0 a A 1.414214 | ||
# 1 b B 1.414214 | ||
|
||
assert_series_equal( | ||
np.sqrt(group_var["X"]), | ||
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. Unless there is a reason for using |
||
group_std["X"]) |
Uh oh!
There was an error while loading. Please reload this page.