-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mroeschke lgtm. one question.
pandas/core/window/expanding.py
Outdated
_GroupByMixin, | ||
_Rolling_and_Expanding, | ||
_shared_docs, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same?
Doesn't need to be part of this PR, but could use your input: I've been wondering if it makes sense to put window and resample into groupby/, or otherwise organize in a way to denote that those two modules depend on groupby/ |
@jbrockmendel definitely. I imagine a lot of the aggregation functions could be collapsed as well if rolling, resample, and groupby lived under the same umbrella. |
this would be too much currently: each of these is already a tremendous amount of tests and code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, very light comments, ping on green.
pandas/core/generic.py
Outdated
@@ -10690,9 +10690,13 @@ def _add_series_or_dataframe_operations(cls): | |||
the doc strings again. | |||
""" | |||
|
|||
from pandas.core import window as rwindow | |||
from pandas.core.window import ( | |||
ewm as lib_ewm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually call the _libs imports like libwindow (etc), so is there a reason you can't just
from pandas.core.window import ewm, expanding, rolling
? (or else I guess would be ok to call libewm, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just directly import what you need from these modules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a RecursionError
since the defined functions here are:
def rolling(...):
return rolling(...)
cls.rolling = rolling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I was able to use more direct imports, and all green.
pandas/core/generic.py
Outdated
@@ -10703,8 +10705,24 @@ def rolling( | |||
axis=0, | |||
closed=None, | |||
): | |||
if not isinstance(self, (ABCSeries, ABCDataFrame)): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm other than some comments, ping on green.
pandas/core/generic.py
Outdated
@@ -10703,8 +10705,24 @@ def rolling( | |||
axis=0, | |||
closed=None, | |||
): | |||
if not isinstance(self, (ABCSeries, ABCDataFrame)): |
There was a problem hiding this comment.
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?
pandas/core/window/__init__.py
Outdated
@@ -0,0 +1,3 @@ | |||
from pandas.core.window.ewm import EWM # noqa:F401 | |||
from pandas.core.window.expanding import Expanding # noqa:F401 |
There was a problem hiding this comment.
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)
@@ -5,7 +5,7 @@ | |||
|
|||
import pandas as pd | |||
from pandas import DataFrame, Series | |||
import pandas.core.window as rwindow | |||
from pandas.core.window.expanding import Expanding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. this should be
from pandas.core.window import Expanding
pandas/tests/window/test_ewm.py
Outdated
@@ -4,7 +4,7 @@ | |||
from pandas.errors import UnsupportedFunctionCall | |||
|
|||
from pandas import DataFrame, Series | |||
import pandas.core.window as rwindow | |||
from pandas.core.window.ewm import EWM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pandas.core.window import EWM
Note that #27767 was just merged so need to account for that in rebase |
yep this needs a rebase, ping on green. |
Ping all green. |
thanks @mroeschke did we have an issue for this? if so pls close it |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Splits
pandas/core/window.py
into more logical division of:pandas/core/window/rolling.py
pandas/core/window/expanding.py
pandas/core/window/ewm.py
pandas/core/window/common.py