Skip to content

Commit 1a3f76f

Browse files
committed
remove get_groupby
1 parent af073c1 commit 1a3f76f

File tree

5 files changed

+13
-60
lines changed

5 files changed

+13
-60
lines changed

pandas/core/frame.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin as DatetimeLikeArray
9494
from pandas.core.arrays.sparse import SparseFrameAccessor
9595
from pandas.core.generic import NDFrame, _shared_docs
96-
from pandas.core.groupby import generic as grp_generic
96+
from pandas.core.groupby import generic as groupby_generic
9797
from pandas.core.indexes import base as ibase
9898
from pandas.core.indexes.api import Index, ensure_index, ensure_index_from_sequences
9999
from pandas.core.indexes.datetimes import DatetimeIndex
@@ -5572,13 +5572,13 @@ def groupby(
55725572
group_keys: bool = True,
55735573
squeeze: bool = False,
55745574
observed: bool = False,
5575-
) -> "grp_generic.DataFrameGroupBy":
5575+
) -> "groupby_generic.DataFrameGroupBy":
55765576

55775577
if level is None and by is None:
55785578
raise TypeError("You have to supply one of 'by' and 'level'")
55795579
axis = self._get_axis_number(axis)
55805580

5581-
return grp_generic.DataFrameGroupBy(
5581+
return groupby_generic.DataFrameGroupBy(
55825582
obj=self,
55835583
keys=by,
55845584
axis=axis,

pandas/core/groupby/generic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
GroupBy,
6060
_apply_docs,
6161
_transform_template,
62-
get_groupby,
6362
)
6463
from pandas.core.indexes.api import Index, MultiIndex, all_indexes_same
6564
import pandas.core.indexes.base as ibase
@@ -1035,7 +1034,7 @@ def _cython_agg_blocks(
10351034
# reductions; see GH#28949
10361035
obj = obj.iloc[:, 0]
10371036

1038-
s = get_groupby(obj, self.grouper)
1037+
s = obj.groupby(self.grouper)
10391038
try:
10401039
result = s.aggregate(lambda x: alt(x, axis=self.axis))
10411040
except TypeError:

pandas/core/groupby/groupby.py

-46
Original file line numberDiff line numberDiff line change
@@ -2510,49 +2510,3 @@ def _reindex_output(
25102510

25112511

25122512
GroupBy._add_numeric_operations()
2513-
2514-
2515-
@Appender(GroupBy.__doc__)
2516-
def get_groupby(
2517-
obj: NDFrame,
2518-
by: Optional[_KeysArgType] = None,
2519-
axis: int = 0,
2520-
level=None,
2521-
grouper: "Optional[ops.BaseGrouper]" = None,
2522-
exclusions=None,
2523-
selection=None,
2524-
as_index: bool = True,
2525-
sort: bool = True,
2526-
group_keys: bool = True,
2527-
squeeze: bool = False,
2528-
observed: bool = False,
2529-
mutated: bool = False,
2530-
):
2531-
2532-
klass: Union[Type["SeriesGroupBy"], Type["DataFrameGroupBy"]]
2533-
if isinstance(obj, Series):
2534-
from pandas.core.groupby.generic import SeriesGroupBy
2535-
2536-
klass = SeriesGroupBy
2537-
elif isinstance(obj, DataFrame):
2538-
from pandas.core.groupby.generic import DataFrameGroupBy
2539-
2540-
klass = DataFrameGroupBy
2541-
else:
2542-
raise TypeError(f"invalid type: {obj}")
2543-
2544-
return klass(
2545-
obj=obj,
2546-
keys=by,
2547-
axis=axis,
2548-
level=level,
2549-
grouper=grouper,
2550-
exclusions=exclusions,
2551-
selection=selection,
2552-
as_index=as_index,
2553-
sort=sort,
2554-
group_keys=group_keys,
2555-
squeeze=squeeze,
2556-
observed=observed,
2557-
mutated=mutated,
2558-
)

pandas/core/resample.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pandas.core.generic import _shared_docs
2121
from pandas.core.groupby.base import GroupByMixin
2222
from pandas.core.groupby.generic import SeriesGroupBy
23-
from pandas.core.groupby.groupby import GroupBy, _GroupBy, _pipe_template, get_groupby
23+
from pandas.core.groupby.groupby import GroupBy, _GroupBy, _pipe_template
2424
from pandas.core.groupby.grouper import Grouper
2525
from pandas.core.groupby.ops import BinGrouper
2626
from pandas.core.indexes.datetimes import DatetimeIndex, date_range
@@ -334,7 +334,7 @@ def _gotitem(self, key, ndim, subset=None):
334334
grouper = self.grouper
335335
if subset is None:
336336
subset = self.obj
337-
grouped = get_groupby(subset, by=None, grouper=grouper, axis=self.axis)
337+
grouped = subset.groupby(by=None, grouper=grouper, axis=self.axis)
338338

339339
# try the key selection
340340
try:
@@ -353,7 +353,7 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
353353

354354
obj = self._selected_obj
355355

356-
grouped = get_groupby(obj, by=None, grouper=grouper, axis=self.axis)
356+
grouped = obj.groupby(by=None, grouper=grouper, axis=self.axis)
357357

358358
try:
359359
if isinstance(obj, ABCDataFrame) and callable(how):

pandas/tests/window/test_grouper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pandas as pd
55
from pandas import DataFrame, Series
6-
from pandas.core.groupby.groupby import get_groupby
6+
from pandas.core.groupby.generic import DataFrameGroupBy
77
import pandas.util.testing as tm
88

99

@@ -19,13 +19,13 @@ def test_mutated(self):
1919
self.frame.groupby("A", foo=1)
2020

2121
g = self.frame.groupby("A")
22-
assert not g.mutated
23-
g = get_groupby(self.frame, by="A", mutated=True)
24-
assert g.mutated
22+
assert g.mutated is False
23+
g = DataFrameGroupBy(self.frame, keys="A", mutated=True)
24+
assert g.mutated is True
2525

2626
def test_getitem(self):
2727
g = self.frame.groupby("A")
28-
g_mutated = get_groupby(self.frame, by="A", mutated=True)
28+
g_mutated = DataFrameGroupBy(self.frame, keys="A", mutated=True)
2929

3030
expected = g_mutated.B.apply(lambda x: x.rolling(2).mean())
3131

@@ -46,7 +46,7 @@ def test_getitem_multiple(self):
4646
# GH 13174
4747
g = self.frame.groupby("A")
4848
r = g.rolling(2)
49-
g_mutated = get_groupby(self.frame, by="A", mutated=True)
49+
g_mutated = DataFrameGroupBy(self.frame, keys="A", mutated=True)
5050
expected = g_mutated.B.apply(lambda x: x.rolling(2).count())
5151

5252
result = r.B.count()

0 commit comments

Comments
 (0)