-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow rolling API to accept BaseIndexer subclass #2
Conversation
closing and opening to trigger travis |
ok looks like travis is connected |
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. |
Thanks for setting up Travis, Jeff. |
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 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.
pandas/_libs/_window.py
Outdated
|
||
class BaseIndexer(abc.ABC): | ||
|
||
def __init__(self, index, offset, keys): |
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.
whatever you can type would be great
pandas/_libs/_window.py
Outdated
|
||
Parameters | ||
---------- | ||
kwargs |
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.
can we explicity set the kwargs?
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 think we want to allow indexer authors to pass arbitrary data here.
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.
Scratch that, these should be explicit.
pandas/core/window.py
Outdated
@@ -11,6 +11,7 @@ | |||
import numpy as np | |||
|
|||
import pandas._libs.window as libwindow | |||
import pandas._libs._window as libwindow_refactor |
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.
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 |
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.
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
pandas/tests/test_window.py
Outdated
@@ -54,6 +56,38 @@ def arithmetic_win_operators(request): | |||
return request.param | |||
|
|||
|
|||
@pytest.fixture(params=['right', 'left', 'both', 'neither']) |
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.
some of this seems a good candidate for a pre-cursor PR to master (the fixtures)
pandas/tests/test_window.py
Outdated
@@ -4154,3 +4188,20 @@ def test_rolling_cov_offset(self): | |||
|
|||
expected2 = ss.rolling(3, min_periods=1).cov() | |||
tm.assert_series_equal(result, expected2) | |||
|
|||
|
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.
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 |
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.
What is the type of window here? It looks like it can be a sequence or an integer?
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.
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.
pandas/tests/test_window.py
Outdated
@@ -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: |
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 class isn't necessary. Since we have pytest
there's really no reason not to use top-level-function-style tests.
pandas/_libs/_window.py
Outdated
window | ||
|
||
""" | ||
return NotImplemented |
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 doesn't need to return anything.
This PR just allows the current rolling API to accept BaseIndexer subclasses in all the validation checks.
Some discussion points about
BaseIndexer
I was thinking that
get_window_bounds
should accept additional keyword arguments from the rolling API likewin_type
,closed
,center
, andwin_type
just in case the author wants to utilize those arguments in the bounds calculation.Since we are instantiating the
BaseIndexer
before passing it intorolling
, I assumedBaseIndexer
would be accepting theindex
,offset
, andkeys
in the init.Any feedback welcome!