Skip to content

(Datetime|Timedelta)Index +/- np.nan #19274

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
jbrockmendel opened this issue Jan 17, 2018 · 0 comments · Fixed by #19277
Closed

(Datetime|Timedelta)Index +/- np.nan #19274

jbrockmendel opened this issue Jan 17, 2018 · 0 comments · Fixed by #19277
Labels
Bug 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

AFAICT this is now the last thing standing between us and getting rid of ops._Op and ops._TimeOp. Series ops currently case np.nan to pd.NaT whereas Index ops treat it as a float and raise a TypeError.

tdi = pd.TimedeltaIndex(['1 Day'])
ser = pd.Series(tdi)

>>> tdi + np.nan
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'TimedeltaIndex' and 'float'

>>> ser + np.nan
0   NaT
dtype: timedelta64[ns]

Note also that the behavior of Series[datetime64] has changed since 0.22.0:

0.22.0:

dti = pd.date_range('2016-01-01', periods=2)
ser = pd.Series(dti)

>>> dti - np.nan
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'DatetimeIndex' and 'float'

>>> ser - np.nan
0   NaT
1   NaT
dtype: timedelta64[ns]

# Both raise on addition, assuming that np.nan gets cast to pd.NaT wearing its datetime hat.

ATM ser - np.nan also raises, since that now delegates to the DatetimeIndex op.

@jbrockmendel jbrockmendel mentioned this issue Jan 17, 2018
4 tasks
@jreback jreback added Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type labels Jan 17, 2018
@jreback jreback modified the milestones: Next Major Release, 0.23.0 Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants