Skip to content

Commit ec9a09c

Browse files
committed
simplify groupby's std method
1 parent 79f41cc commit ec9a09c

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

pandas/core/groupby.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,7 @@ def std(self, ddof=1):
695695
For multiple groupings, the result index will be a MultiIndex
696696
"""
697697
# todo, implement at cython level?
698-
if ddof == 1:
699-
return self._cython_agg_general('std')
700-
else:
701-
self._set_selection_from_grouper()
702-
f = lambda x: x.std(ddof=ddof)
703-
return self._python_agg_general(f)
698+
return np.sqrt(self.var(ddof=ddof))
704699

705700
def var(self, ddof=1):
706701
"""
@@ -1332,7 +1327,6 @@ def get_group_levels(self):
13321327
'name': 'group_median'
13331328
},
13341329
'var': 'group_var',
1335-
'std': 'group_var',
13361330
'first': {
13371331
'name': 'group_nth',
13381332
'f': lambda func, a, b, c, d: func(a, b, c, d, 1)
@@ -1341,10 +1335,6 @@ def get_group_levels(self):
13411335
'count': 'group_count',
13421336
}
13431337

1344-
_cython_transforms = {
1345-
'std': np.sqrt,
1346-
}
1347-
13481338
_cython_arity = {
13491339
'ohlc': 4, # OHLC
13501340
}
@@ -1455,7 +1445,6 @@ def aggregate(self, values, how, axis=0):
14551445

14561446
def _aggregate(self, result, counts, values, how, is_numeric):
14571447
agg_func, dtype = self._get_aggregate_function(how, values)
1458-
trans_func = self._cython_transforms.get(how, lambda x: x)
14591448

14601449
comp_ids, _, ngroups = self.group_info
14611450
if values.ndim > 3:
@@ -1469,7 +1458,7 @@ def _aggregate(self, result, counts, values, how, is_numeric):
14691458
else:
14701459
agg_func(result, counts, values, comp_ids)
14711460

1472-
return trans_func(result)
1461+
return result
14731462

14741463
def agg_series(self, obj, func):
14751464
try:
@@ -1669,7 +1658,6 @@ def names(self):
16691658
'min': 'group_min_bin',
16701659
'max': 'group_max_bin',
16711660
'var': 'group_var_bin',
1672-
'std': 'group_var_bin',
16731661
'ohlc': 'group_ohlc',
16741662
'first': {
16751663
'name': 'group_nth_bin',
@@ -1688,7 +1676,6 @@ def names(self):
16881676
def _aggregate(self, result, counts, values, how, is_numeric=True):
16891677

16901678
agg_func, dtype = self._get_aggregate_function(how, values)
1691-
trans_func = self._cython_transforms.get(how, lambda x: x)
16921679

16931680
if values.ndim > 3:
16941681
# punting for now
@@ -1699,7 +1686,7 @@ def _aggregate(self, result, counts, values, how, is_numeric=True):
16991686
else:
17001687
agg_func(result, counts, values, self.bins)
17011688

1702-
return trans_func(result)
1689+
return result
17031690

17041691
def agg_series(self, obj, func):
17051692
dummy = obj[:0]

0 commit comments

Comments
 (0)