Skip to content

Commit e85ef7d

Browse files
committed
CLN refactor with _apply_to_column_groupbys
1 parent 74e4544 commit e85ef7d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pandas/core/groupby.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,6 @@ def ohlc(self):
430430
431431
For multiple groupings, the result index will be a MultiIndex
432432
"""
433-
if isinstance(self.obj, com.ABCDataFrame):
434-
from pandas.tools.merge import concat
435-
return concat((col_groupby._cython_agg_general('ohlc')
436-
for _, col_groupby in self._iterate_column_groupbys()),
437-
keys=self.obj.columns,
438-
axis=1)
439-
440433
return self._cython_agg_general('ohlc')
441434

442435
def nth(self, n):
@@ -2245,6 +2238,20 @@ def _iterate_column_groupbys(self):
22452238
grouper=self.grouper,
22462239
exclusions=self.exclusions)
22472240

2241+
def _apply_to_column_groupbys(self, func):
2242+
from pandas.tools.merge import concat
2243+
return concat((func(col_groupby)
2244+
for _, col_groupby in self._iterate_column_groupbys()),
2245+
keys=self.obj.columns,
2246+
axis=1)
2247+
2248+
def ohlc(self):
2249+
"""
2250+
Compute sum of values, excluding missing values
2251+
2252+
For multiple groupings, the result index will be a MultiIndex
2253+
"""
2254+
return self._apply_to_column_groupbys(lambda x: x._cython_agg_general('ohlc'))
22482255

22492256
from pandas.tools.plotting import boxplot_frame_groupby
22502257
DataFrameGroupBy.boxplot = boxplot_frame_groupby

0 commit comments

Comments
 (0)