Skip to content

Allow rolling API to accept BaseIndexer subclass #2

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

Conversation

mroeschke
Copy link
Collaborator

This PR just allows the current rolling API to accept BaseIndexer subclasses in all the validation checks.

Some discussion points about BaseIndexer

  1. I was thinking that get_window_bounds should accept additional keyword arguments from the rolling API like win_type, closed, center, and win_type just in case the author wants to utilize those arguments in the bounds calculation.

  2. Since we are instantiating the BaseIndexer before passing it into rolling, I assumed BaseIndexer would be accepting the index, offset, and keys in the init.

Any feedback welcome!

@jreback
Copy link
Collaborator

jreback commented Jul 2, 2019

closing and opening to trigger travis

@jreback jreback closed this Jul 2, 2019
@jreback jreback reopened this Jul 2, 2019
@jreback
Copy link
Collaborator

jreback commented Jul 2, 2019

ok looks like travis is connected

@jreback
Copy link
Collaborator

jreback commented Jul 2, 2019

I also added some branches to prevent force pushing / deletion but no other restrictions: https://github.com/twosigma/pandas/settings/branches

can edit / change if needed.

@mroeschke
Copy link
Collaborator Author

Thanks for setting up Travis, Jeff.

Copy link
Collaborator

@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 so far. As mentioned, doing a couple of pre-cursor PRs to master makes sense to add typing & move tests to the appropriate place make sense.


class BaseIndexer(abc.ABC):

def __init__(self, index, offset, keys):
Copy link
Collaborator

Choose a reason for hiding this comment

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

whatever you can type would be great


Parameters
----------
kwargs
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we explicity set the kwargs?

Copy link

Choose a reason for hiding this comment

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

I think we want to allow indexer authors to pass arbitrary data here.

Copy link

Choose a reason for hiding this comment

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

Scratch that, these should be explicit.

@@ -11,6 +11,7 @@
import numpy as np

import pandas._libs.window as libwindow
import pandas._libs._window as libwindow_refactor
Copy link
Collaborator

Choose a reason for hiding this comment

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

so I would either do this directly in .window or name this something non-private (as its already private). Note that if say refactoring needs to be done to make things cleaner we can do pre-cursors to master.

@@ -451,14 +452,19 @@ class Window(_Window):

Parameters
----------
window : int, or offset
window : int, offset, or BaseIndexer subclass
Copy link
Collaborator

Choose a reason for hiding this comment

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

ideally type as much as possible (again I know that things are not typed now), maybe makes sense to do a pre-cursor to type what we have now

@@ -54,6 +56,38 @@ def arithmetic_win_operators(request):
return request.param


@pytest.fixture(params=['right', 'left', 'both', 'neither'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

some of this seems a good candidate for a pre-cursor PR to master (the fixtures)

@@ -4154,3 +4188,20 @@ def test_rolling_cov_offset(self):

expected2 = ss.rolling(3, min_periods=1).cov()
tm.assert_series_equal(result, expected2)


Copy link
Collaborator

Choose a reason for hiding this comment

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

not averse to actually putting the tests in a separate file (may make review easier).

so I think a pre-cursor PR to move pandas/tests/test_window.py -> pandas/tests/window/test_window.py makes sense (then we can add on things in an easy namespace)

@@ -2775,6 +2788,8 @@ def _get_center_of_mass(comass, span, halflife, alpha):


def _offset(window, center):
# TODO: (MATT) If the window is a BaseIndexer subclass,
# we need to pass in the materialized window
Copy link

Choose a reason for hiding this comment

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

What is the type of window here? It looks like it can be a sequence or an integer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. After a light audit, I anticipate the materialized window may be passed here and other times and Indexer class might be passed here.

Overall I think this routine is for label formatting.

@@ -4749,3 +4782,20 @@ def test_rolling_cov_offset(self):

expected2 = ss.rolling(3, min_periods=1).cov()
tm.assert_series_equal(result, expected2)


class TestCustomIndexer:
Copy link

Choose a reason for hiding this comment

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

This class isn't necessary. Since we have pytest there's really no reason not to use top-level-function-style tests.

window

"""
return NotImplemented
Copy link

Choose a reason for hiding this comment

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

This doesn't need to return anything.

@mroeschke mroeschke changed the title WIP: Allow rolling API to accept BaseIndexer subclass Allow rolling API to accept BaseIndexer subclass Jul 12, 2019
@mroeschke mroeschke merged commit 609433d into feature/generalized_window_operations Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants