Skip to content

REF: pandas/core/window.py into multiple files #27736

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 8 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion doc/source/reference/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
======
Window
======
.. currentmodule:: pandas.core.window

Rolling objects are returned by ``.rolling`` calls: :func:`pandas.DataFrame.rolling`, :func:`pandas.Series.rolling`, etc.
Expanding objects are returned by ``.expanding`` calls: :func:`pandas.DataFrame.expanding`, :func:`pandas.Series.expanding`, etc.
EWM objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.

Standard moving window functions
--------------------------------
.. currentmodule:: pandas.core.window.rolling

.. autosummary::
:toctree: api/

Expand All @@ -38,6 +39,8 @@ Standard moving window functions

Standard expanding window functions
-----------------------------------
.. currentmodule:: pandas.core.window.expanding

.. autosummary::
:toctree: api/

Expand All @@ -59,6 +62,8 @@ Standard expanding window functions

Exponentially-weighted moving window functions
----------------------------------------------
.. currentmodule:: pandas.core.window.ewm

.. autosummary::
:toctree: api/

Expand Down
40 changes: 31 additions & 9 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10690,9 +10690,11 @@ def _add_series_or_dataframe_operations(cls):
the doc strings again.
"""

from pandas.core import window as rwindow
from pandas.core.window.ewm import EWM
from pandas.core.window.expanding import Expanding
from pandas.core.window.rolling import Rolling, Window

@Appender(rwindow.rolling.__doc__)
@Appender(Rolling.__doc__)
def rolling(
self,
window,
Expand All @@ -10703,8 +10705,24 @@ def rolling(
axis=0,
closed=None,
):
if not isinstance(self, (ABCSeries, ABCDataFrame)):
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this check? would prefer not to see ABCSeries and ABCDataFrame in core.generic.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this should be inside Rolling constructor. Let's try to keep this diff as copy-paste as possible though & I don't think this was on the original diff at all?

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 was in the original "top level" rolling function that would be imported here, but I found a better place to put this check.

raise TypeError("invalid type: {}".format(type(self)))

axis = self._get_axis_number(axis)
return rwindow.rolling(

if win_type is not None:
return Window(
self,
window=window,
min_periods=min_periods,
center=center,
win_type=win_type,
on=on,
axis=axis,
closed=closed,
)

return Rolling(
self,
window=window,
min_periods=min_periods,
Expand All @@ -10717,16 +10735,17 @@ def rolling(

cls.rolling = rolling

@Appender(rwindow.expanding.__doc__)
@Appender(Expanding.__doc__)
def expanding(self, min_periods=1, center=False, axis=0):
if not isinstance(self, (ABCSeries, ABCDataFrame)):
raise TypeError("invalid type: {}".format(type(self)))

axis = self._get_axis_number(axis)
return rwindow.expanding(
self, min_periods=min_periods, center=center, axis=axis
)
return Expanding(self, min_periods=min_periods, center=center, axis=axis)

cls.expanding = expanding

@Appender(rwindow.ewm.__doc__)
@Appender(EWM.__doc__)
def ewm(
self,
com=None,
Expand All @@ -10738,8 +10757,11 @@ def ewm(
ignore_na=False,
axis=0,
):
if not isinstance(self, (ABCSeries, ABCDataFrame)):
raise TypeError("invalid type: {}".format(type(self)))

axis = self._get_axis_number(axis)
return rwindow.ewm(
return EWM(
self,
com=com,
span=span,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ def rolling(self, *args, **kwargs):
"""
Return a rolling grouper, providing rolling functionality per group.
"""
from pandas.core.window import RollingGroupby
from pandas.core.window.rolling import RollingGroupby

return RollingGroupby(self, *args, **kwargs)

Expand All @@ -1574,7 +1574,7 @@ def expanding(self, *args, **kwargs):
Return an expanding grouper, providing expanding
functionality per group.
"""
from pandas.core.window import ExpandingGroupby
from pandas.core.window.expanding import ExpandingGroupby

return ExpandingGroupby(self, *args, **kwargs)

Expand Down
3 changes: 3 additions & 0 deletions pandas/core/window/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pandas.core.window.ewm import EWM # noqa:F401
from pandas.core.window.expanding import Expanding # 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.

I would add ExpandingGroupby & RollingGroupby here as well; we want to export the 'public' interface to the rest of pandas, so IOW, we don't have any where that needs to reach into pandas.core.window.*, then just import from pandas.core.window (this is all for inside of pandas)

from pandas.core.window.rolling import Rolling, Window # noqa:F401
Loading