Skip to content

Move GroupBy to Submodule and Add FutureWarning #20506

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

Merged
merged 17 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/core/groupby/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import warnings

# TODO: Remove after 0.XX.x
warnings.warn("'pandas.core.groupby' has moved. Use "
"'pandas.core.groupby.groupby' instead", FutureWarning,
stacklevel=2)

from pandas.core.groupby.groupby import Grouper # noqa: F401
from pandas.core.groupby.groupby import groupby # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u import these in 1 statement

from pandas.core.groupby.groupby import BinGrouper # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only put public functions here. If something is needed internally then change the reference to it.

from pandas.core.groupby.groupby import _GroupBy # noqa: F401
from pandas.core.groupby.groupby import GroupBy # noqa: F401
from pandas.core.groupby.groupby import SeriesGroupBy # noqa: F401
from pandas.core.groupby.groupby import _pipe_template # noqa: F401
from pandas.core.groupby.groupby import PanelGroupBy # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all these imports actually needed?

just change where they r used

from pandas.core.groupby.groupby import Grouping # noqa: F401
from pandas.core.groupby.groupby import SpecificationError # noqa: F401
from pandas.core.groupby.groupby import DataError # noqa: F401
from pandas.core.groupby.groupby import generate_bins_generic # noqa: F401
File renamed without changes.
15 changes: 14 additions & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_deprecation_cdaterange(self):
cdate_range('2017-01-01', '2017-12-31')


class TestCategoricalMove(object):
class TestModuleMoves(object):

def test_categorical_move(self):
# May have been cached by another import, e.g. pickle tests.
Expand All @@ -251,3 +251,16 @@ def test_categorical_move(self):

with tm.assert_produces_warning(FutureWarning):
from pandas.core.categorical import CategoricalDtype # noqa

@pytest.mark.parametrize("attr", [
"Grouper", "groupby", "BinGrouper", "Grouper", "_GroupBy", "GroupBy",
"SeriesGroupBy", "_pipe_template", "PanelGroupBy", "Grouping",
"SpecificationError", "DataError", "generate_bins_generic"])
def test_groupby_move(self, attr):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be straightforward to combine with the method above if we wanted one test accepting a module / list of objects to test the deprecation for

# May have been cached by another import, e.g. pickle tests.
sys.modules.pop("pandas.core.groupby", None)

with tm.assert_produces_warning(FutureWarning):
import pandas.core.groupby as grpby # noqa

getattr(grpby, attr)