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

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke commented Aug 4, 2019

  • tests added / passed
  • passes black pandas
  • passes 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

@mroeschke mroeschke added Refactor Internal refactoring of code Window rolling, ewma, expanding labels Aug 4, 2019
Copy link
Member

@simonjayhawkins simonjayhawkins left a 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.

_GroupByMixin,
_Rolling_and_Expanding,
_shared_docs,
)
Copy link
Member

Choose a reason for hiding this comment

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

same?

@jbrockmendel
Copy link
Member

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/

@mroeschke
Copy link
Member Author

@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.

@jreback
Copy link
Contributor

jreback commented Aug 4, 2019

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/

this would be too much currently: each of these is already a tremendous amount of tests and code
nesting more doesn’t help

Copy link
Contributor

@jreback jreback left a 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.

@@ -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,
Copy link
Contributor

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)

Copy link
Contributor

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?

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 caused a RecursionError since the defined functions here are:

def rolling(...):
    return rolling(...)

cls.rolling = rolling

Copy link
Member Author

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.

@jreback jreback added this to the 1.0 milestone Aug 4, 2019
@@ -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.

Copy link
Contributor

@jreback jreback left a 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.

@@ -10703,8 +10705,24 @@ def rolling(
axis=0,
closed=None,
):
if not isinstance(self, (ABCSeries, ABCDataFrame)):
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?

@@ -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)

@@ -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
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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

@WillAyd
Copy link
Member

WillAyd commented Aug 6, 2019

Note that #27767 was just merged so need to account for that in rebase

@jreback
Copy link
Contributor

jreback commented Aug 6, 2019

yep this needs a rebase, ping on green.

@mroeschke
Copy link
Member Author

Ping all green.

@jreback jreback merged commit 3bf35c6 into pandas-dev:master Aug 7, 2019
@jreback
Copy link
Contributor

jreback commented Aug 7, 2019

thanks @mroeschke

did we have an issue for this? if so pls close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants