Skip to content

Commit

Permalink
Move GroupBy to Submodule and Add FutureWarning (pandas-dev#20506)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored and jreback committed Apr 2, 2018
1 parent fac2ef1 commit 5edc5c4
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pandas.core.algorithms import factorize, unique, value_counts
from pandas.core.dtypes.missing import isna, isnull, notna, notnull
from pandas.core.arrays import Categorical
from pandas.core.groupby import Grouper
from pandas.core.groupby.groupby import Grouper
from pandas.io.formats.format import set_eng_float_format
from pandas.core.index import (Index, CategoricalIndex, Int64Index,
UInt64Index, RangeIndex, Float64Index,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6589,7 +6589,7 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
resample : Convenience method for frequency conversion and resampling
of time series.
"""
from pandas.core.groupby import groupby
from pandas.core.groupby.groupby import groupby

if level is None and by is None:
raise TypeError("You have to supply one of 'by' and 'level'")
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/groupby/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# flake8: noqa
from pandas.core.groupby.groupby import (
Grouper, GroupBy, SeriesGroupBy, DataFrameGroupBy
)
File renamed without changes.
2 changes: 1 addition & 1 deletion pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def groupby(self, function, axis='major'):
-------
grouped : PanelGroupBy
"""
from pandas.core.groupby import PanelGroupBy
from pandas.core.groupby.groupby import PanelGroupBy
axis = self._get_axis_number(axis)
return PanelGroupBy(self, function, axis=axis)

Expand Down
7 changes: 4 additions & 3 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import pandas as pd
from pandas.core.base import GroupByMixin

from pandas.core.groupby import (BinGrouper, Grouper, _GroupBy, GroupBy,
SeriesGroupBy, groupby, PanelGroupBy,
_pipe_template)
from pandas.core.groupby.groupby import (
BinGrouper, Grouper, _GroupBy, GroupBy, SeriesGroupBy, groupby,
PanelGroupBy, _pipe_template
)

from pandas.tseries.frequencies import to_offset, is_subperiod, is_superperiod
from pandas.core.indexes.datetimes import DatetimeIndex, date_range
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pandas.core.reshape.concat import concat
from pandas.core.series import Series
from pandas.core.groupby import Grouper
from pandas.core.groupby.groupby import Grouper
from pandas.core.reshape.util import cartesian_product
from pandas.core.index import Index, _get_objs_combined_axis
from pandas.compat import range, lrange, zip
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas as pd

from pandas import concat, DataFrame, Index, MultiIndex, Series
from pandas.core.groupby import Grouping, SpecificationError
from pandas.core.groupby.groupby import Grouping, SpecificationError
from pandas.compat import OrderedDict
import pandas.util.testing as tm

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/aggregate/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pandas import (bdate_range, DataFrame, Index, Series, Timestamp,
Timedelta, NaT)
from pandas.core.groupby import DataError
from pandas.core.groupby.groupby import DataError
import pandas.util.testing as tm


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/aggregate/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandas import (
date_range, DataFrame, Index, MultiIndex, PeriodIndex, period_range, Series
)
from pandas.core.groupby import SpecificationError
from pandas.core.groupby.groupby import SpecificationError
from pandas.io.formats.printing import pprint_thing
import pandas.util.testing as tm

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_bin_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup_method(self, method):
self.bins = np.array([3, 6], dtype=np.int64)

def test_generate_bins(self):
from pandas.core.groupby import generate_bins_generic
from pandas.core.groupby.groupby import generate_bins_generic
values = np.array([1, 2, 3, 4, 5, 6], dtype=np.int64)
binner = np.array([0, 3, 6, 9], dtype=np.int64)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_groupby_grouper_f_sanity_checked(self):
pytest.raises(AssertionError, ts.groupby, lambda key: key[0:6])

def test_grouping_error_on_multidim_input(self):
from pandas.core.groupby import Grouping
from pandas.core.groupby.groupby import Grouping
pytest.raises(ValueError,
Grouping, self.df.index, self.df[['A', 'A']])

Expand Down
25 changes: 14 additions & 11 deletions pandas/tests/groupby/test_timegrouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def test_groupby_with_timegrouper(self):
result3 = df.groupby(pd.Grouper(freq='5D')).sum()
assert_frame_equal(result3, expected)

def test_groupby_with_timegrouper_methods(self):
@pytest.mark.parametrize("should_sort", [True, False])
def test_groupby_with_timegrouper_methods(self, should_sort):
# GH 3881
# make sure API of timegrouper conforms

df_original = pd.DataFrame({
df = pd.DataFrame({
'Branch': 'A A A A A B'.split(),
'Buyer': 'Carl Mark Carl Joe Joe Carl'.split(),
'Quantity': [1, 3, 5, 8, 9, 3],
Expand All @@ -75,16 +76,18 @@ def test_groupby_with_timegrouper_methods(self):
]
})

df_sorted = df_original.sort_values(by='Quantity', ascending=False)
if should_sort:
df = df.sort_values(by='Quantity', ascending=False)

for df in [df_original, df_sorted]:
df = df.set_index('Date', drop=False)
g = df.groupby(pd.Grouper(freq='6M'))
assert g.group_keys
assert isinstance(g.grouper, pd.core.groupby.BinGrouper)
groups = g.groups
assert isinstance(groups, dict)
assert len(groups) == 3
df = df.set_index('Date', drop=False)
g = df.groupby(pd.Grouper(freq='6M'))
assert g.group_keys

import pandas.core.groupby.groupby
assert isinstance(g.grouper, pandas.core.groupby.groupby.BinGrouper)
groups = g.groups
assert isinstance(groups, dict)
assert len(groups) == 3

def test_timegrouper_with_reg_groups(self):

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .common import MixIn, assert_fp_equal

from pandas.util.testing import assert_frame_equal, assert_series_equal
from pandas.core.groupby import DataError
from pandas.core.groupby.groupby import DataError
from pandas.core.config import option_context


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pandas.core.dtypes.generic import ABCSeries, ABCDataFrame
from pandas.compat import range, lrange, zip, product, OrderedDict
from pandas.errors import UnsupportedFunctionCall
from pandas.core.groupby import DataError
from pandas.core.groupby.groupby import DataError
import pandas.core.common as com

from pandas.tseries.frequencies import to_offset
Expand Down

0 comments on commit 5edc5c4

Please sign in to comment.