-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series[timdelta64].var() should _not_ work #28289
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
pandas/core/series.py
Outdated
@@ -4012,6 +4012,13 @@ def _reduce( | |||
If we have an ndarray as a value, then simply perform the operation, | |||
otherwise delegate to the object. | |||
""" | |||
if name == "var" and is_timedelta64_dtype(self.dtype): | |||
raise TypeError( |
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.
is there anyway you can do this in nanops instead? it is very awkward to do 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.
Looks like this is no longer necessary, removed.
conflict, plus a comment above |
pandas/core/nanops.py
Outdated
if is_timedelta64_dtype(values.dtype): | ||
# std is well-behaved, but var is not | ||
if mask is None: | ||
mask = isna(values) |
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 this might be better fixed if we have nanvar call _get_values (which already does this masking & type conversion); its the only routine which doesn't I think (well maybe sem).
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.
The problem with that is that we need different behavior for nanstd vs nanvar
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 you try to address this
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.
Well, no. We have @disallow("M8", "m8")
on nanvar
, so if we don't do this here, we'll raise as soon as we call nanvar
with non-casted values.
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 am concerned about this code duplicatio of _get_values.
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'll double 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.
Yep, turns out we can use _get_values. updated
gentle ping. more reductions to implement after this |
I don't think my comments above were addressed. the code change is duplicative, if you can find a way to combine with the existing routines. |
I replied to your comment suggesting that nanstd should go through nanvar: that is not a viable option. |
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.
small followup, otherwise lgtm.
@@ -300,11 +300,14 @@ def test_timedelta_ops(self): | |||
assert result[0] == expected | |||
|
|||
# invalid ops | |||
for op in ["skew", "kurt", "sem", "prod"]: | |||
for op in ["skew", "kurt", "sem", "prod", "var"]: |
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.
let's split this to a separate test that is paramterized (followon)
thanks |
* follow-up to pandas-dev#29314 * followup to pandas-dev#28289
* follow-up to pandas-dev#29314 * followup to pandas-dev#28289
* follow-up to pandas-dev#29314 * followup to pandas-dev#28289
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff