Skip to content
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

Series.__sub__(NaT) vs DatetimeIndex.__sub__(NaT) #18808

Closed
jbrockmendel opened this issue Dec 16, 2017 · 5 comments · Fixed by #19024
Closed

Series.__sub__(NaT) vs DatetimeIndex.__sub__(NaT) #18808

jbrockmendel opened this issue Dec 16, 2017 · 5 comments · Fixed by #19024
Labels
Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Milestone

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Dec 16, 2017

One treats NaT result as datetime, other treats it as timedelta.

>>> dti  = pd.DatetimeIndex([pd.NaT, pd.Timestamp('19900315')])
>>> ser = pd.Series(dti)

>>> dti - pd.NaT
TimedeltaIndex([NaT, NaT], dtype='timedelta64[ns]', freq=None)

>>> ser - pd.NaT
0   NaT
1   NaT
dtype: datetime64[ns]
@gfyoung gfyoung added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type Datetime Datetime data dtype labels Dec 17, 2017
@gfyoung
Copy link
Member

gfyoung commented Dec 17, 2017

Hmmm...that does seem a little inconsistent. Have a look as to why that's happening.

@jreback jreback added this to the Next Major Release milestone Dec 18, 2017
@jreback
Copy link
Contributor

jreback commented Dec 18, 2017

I would argue that the series is wrong here. a sub operation with a DTI-like should always yield a TDI-like.

@jbrockmendel
Copy link
Member Author

I would argue that the series is wrong here. a sub operation with a DTI-like should always yield a TDI-like.

So I can change that and consider it a bugfix as opposed to a Breaking Change?

@jreback
Copy link
Contributor

jreback commented Dec 18, 2017

no its a breaking change, but you can still change it

@jbrockmendel
Copy link
Member Author

Got a fix for this about ready. Two questions.

One: there are a couple of tests in series.test_operators test_datetime64_ops_nat that specifically check for the return type to be datetime64. Sure the behavior isn't intentional?

Two: also in test_datetime64_ops_nat are tests for -pd.NaT + Series[datetime64]. Should that also be changed to return Series[timedelta64]?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Projects
None yet
3 participants