-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Raising TypeError on invalid window when using .rolling #12669 #12718
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1354,6 +1354,8 @@ def _get_center_of_mass(com, span, halflife, alpha): | |
|
||
|
||
def _offset(window, center): | ||
if com.is_float(window): | ||
raise TypeError("Window should be of type Integer, given Float") | ||
if not com.is_integer(window): | ||
window = len(window) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test exists for |
||
offset = (window - 1) / 2. if center else 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,6 +761,9 @@ def test_rolling_median(self): | |
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): | ||
self._check_moment_func(mom.rolling_median, np.median, | ||
name='median') | ||
# GH 12669 | ||
with self.assertRaises(TypeError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a 1-liner explaining what the issue is |
||
pd.DataFrame(np.arange(10)).rolling(2., center=True).median() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use |
||
def test_rolling_min(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a test with a Series as well |
||
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loop thru a couple of things that are unacceptable for |
||
|
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.
It would be better to use
if not com.is_integer(window): raise TypeError
but that will clearly need to happen at a another point in the code, because at this point we accept arrays (see line below)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 needs to happen in the
_Rolling
constructor. ifwindow is not None
then it can be tested for being aninteger
(or raiseTypeError
)