Skip to content

FIX: Scalar timedelta NaT results raise #7661

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

Closed
wants to merge 5 commits into from

Conversation

ischwabacher
Copy link
Contributor

Currently, coercion of scalar results from float to timedelta64[ns] passes through int, which raises when attempting to coerce NaN to NaT.

To reproduce:

import pandas as pd
import numpy as np
pd.Series([np.timedelta64('NaT')]).sum()
# TypeError: reduction operation 'sum' not allowed for this dtype

Currently, coercion of scalar results from `float` to `timedelta64[ns]` passes through `int`, which raises when attempting to coerce `NaN` to `NaT`.

To reproduce:
```python

import pandas as pd
import numpy as np
pd.Series([np.timedelta64('NaT')]).sum()
# TypeError: reduction operation 'sum' not allowed for this dtype
```
@jreback jreback added this to the 0.15.0 milestone Jul 3, 2014
@jreback
Copy link
Contributor

jreback commented Jul 3, 2014

needs tests (put in tests/test_series.py, after the timdelta operations sections. Need to systematically tests these types of ops (both with and w/o NaT). Might also be some tests in tseries/tests/test_timeseries.py/test_timedeltas.py

e.g. sum,mean,max,min, and that raises on things like var,std

Test coverage for ops on `NaT` values is a little better.  The SciPy functions for which operations on `datetime64` and `timedelta64` make sense could be added, but to my knowledge SciPy will currently choke on these anyway.
@ischwabacher
Copy link
Contributor Author

Oh, the problem is that test_nanops.py only covers NaN and ignores NaT. Hrm. Any bets on how much breakage this change is going to reveal?

@ischwabacher
Copy link
Contributor Author

It looks like np.timedelta64('NaT') creates an object of dtype m8 instead of m8[ns], and the isnull can't handle that. Instead of accepting m8, it would probably be better to coerce np.timedelta64('NaT') to np.timedelta64('NaT', 'ns') whenever it's being added to a Pandas object, if that's feasible.

@jreback
Copy link
Contributor

jreback commented Jul 3, 2014

you don't handle m8 like that
it's an integer array; use tslib.iNaT

@ischwabacher
Copy link
Contributor Author

I don't understand what you mean by that. I will see if I can get back to it sometime over the weekend.

@jreback jreback modified the milestones: 0.15.0, 0.15.1 Jul 6, 2014
Note that `print(np.array([pd.tslib.iNaT], dtype='m8[ns]'))` does not display correctly, but its behavior is consistent with being Not-A-Time.
@ischwabacher
Copy link
Contributor Author

OK, clearly I need to wait until I have time to really read this and figure out what's going on.

@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

have a look at tseries/test_timedeltas.py. timedeltas are an odd duck. You generally work on an int64 based series, then take a timedelta64[ns] view. note that almost all tests are skipped for numpy < 1.7 (as its broken) for timedeltas.

@jreback
Copy link
Contributor

jreback commented Sep 4, 2014

@ischwabacher status?

@ischwabacher
Copy link
Contributor Author

Sorry, hectic time at home. I will try to make time for this soon.

@jreback
Copy link
Contributor

jreback commented Sep 14, 2014

closing in favor of #8268

this is already fixed in master with Timedelta refactor

@jreback jreback closed this Sep 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants