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

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

Closed
jbrockmendel opened this Issue Jan 17, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@jbrockmendel
Copy link
Member

commented Jan 17, 2018

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 referenced this issue Jan 17, 2018

Merged

Remove timeop #19277

4 of 4 tasks complete

@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
You can’t perform that action at this time.