-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.to_timedelta handles missing data #5438
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
BUG: pd.to_timedelta handles missing data #5438
Conversation
Another issue lurking...
|
fyi....this test should hold as well:
|
This patch will fix the problem from above need a sequence of tests (you can do in a single method if y ou want, just need these combinations).
where op in
|
@@ -84,6 +85,8 @@ def conv(v): | |||
r = conv(r) | |||
elif r == tslib.iNaT: | |||
return r | |||
elif pd.isnull(r): |
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.
just import isnull from pandas.core.common
Take a look at the comments near my tests. There is still one major issue:
|
|
||
# TODO: This should really pass. | ||
# actual = s1 + NA | ||
# assert_series_equal(actual, sn) |
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's wrong 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.
Traceback (most recent call last):
File "/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/tseries/tests/test_timedeltas.py", line 253, in test_timedelta_ops_with_missing_values
actual = s1 + NA
File "/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/ops.py", line 455, in wrapper
time_converted = _TimeOp.maybe_convert_for_time_op(left, right, name)
File "/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/ops.py", line 424, in maybe_convert_for_time_op
return cls(left, right, name)
File "/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/ops.py", line 258, in __init__
rvalues = self._convert_to_array(right, name=name)
File "/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/ops.py", line 359, in _convert_to_array
" operation".format(pa.array(values).dtype))
TypeError: incompatible type [float64] for a datetime/timedelta operation
I did a PR on your branch...incorporate the last commit..and should be good to go (though may need a couple of comparisons for the fixed tests) |
Thanks. I may have screwed up your PR. Thought I merged it, now don't see it.... |
nm, I see what I did. Thanks again for handling the hard parts of this. Stand by. |
That worked. I added a test to check
and I think apply is returning objects instead of timedelta64[ns]. Is this another case of taking the wrong path?
|
the apply on the series is a separate and thorny topic, basically |
I'll defer for now. This is good enough to be usable. If the latest build passes (it should) this is ready. |
gr8.....go ahead an create the other issue though (FYI look at the test in |
you are going to have to do the skip if np < 1.7 for most/all of those tests. you can possibly check if you should raise in the actual ops....in theory it should work, but not 100 %...numpy 1.6.2 is a bear |
I pre-emptively used |
@jreback Looks like some datetime tests were broken. Will return to this tomorrow. |
@danielballan I did a PR to your branch to fix the last bit of tests.... |
I put this on your PR, @jreback, but I'm duplicating it here: One error left:
|
where is this failing? the current pr passes |
My local copy wasn't quite right. Fine now. Ready to merge. |
^ This is just a rebase to flatten. |
+1 on nice hisrory |
BUG: pd.to_timedelta handles missing data
closes #5437
Updated: Mostly following @jreback's suggestion, but we need
np.timedelta64('NaT')
, notpd.tslib.iNaT
, because numpy cannot castnp.datetime64('NaT')
asnp.timedelta64
type, and throws anAssertionError
.