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

DatetimeIndex + Series[timedelta64] returns DatetimeIndex #18963

Closed
jbrockmendel opened this issue Dec 28, 2017 · 4 comments
Closed

DatetimeIndex + Series[timedelta64] returns DatetimeIndex #18963

jbrockmendel opened this issue Dec 28, 2017 · 4 comments
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timedelta Timedelta data type

Comments

@jbrockmendel
Copy link
Member

This is listed in the roundup #18824 but the behavior has changed since the older issue.

dti = pd.date_range('2017-01-01', periods=2)
ser = pd.Series(pd.TimedeltaIndex(['1 Day', '1Day']))
res1 = dti + ser
res2 = ser + dti
res3 = dti - ser
res4 = -ser + dti

>>> res1
DatetimeIndex(['2017-01-02', '2017-01-03'], dtype='datetime64[ns]', freq=None)
>>> res2
0   2017-01-02
1   2017-01-03
dtype: datetime64[ns]
>>> res3
DatetimeIndex(['2016-12-31', '2017-01-01'], dtype='datetime64[ns]', freq=None)
>>> res4
0   2016-12-31
1   2017-01-01
dtype: datetime64[ns]
@jbrockmendel
Copy link
Member Author

I think there's an easy fix to this in indexes.datetimelike dropping a if isinstance(other, (ABCSeries, ABCDataFrame)): return NotImplemented right at the top of __add__ and __sub__.

@jreback
Copy link
Contributor

jreback commented Dec 28, 2017

seems a bit inconsistent.

@jreback jreback added Difficulty Intermediate Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timedelta Timedelta data type Datetime Datetime data dtype labels Dec 28, 2017
@jreback jreback added this to the Next Major Release milestone Dec 28, 2017
@jbrockmendel
Copy link
Member Author

Same deal for TimedeltaIndex * Series[int]. In fact this is specifically tested (it can't be intentional can it?)

        idx = TimedeltaIndex(np.arange(5, dtype='int64'))
        didx = TimedeltaIndex(np.arange(5, dtype='int64') ** 2)
        [...]
        result = idx * Series(np.arange(5, dtype='int64'))
        tm.assert_index_equal(result, didx)

@jbrockmendel
Copy link
Member Author

jbrockmendel commented Jan 2, 2018

The OP issue is closed by #18884. The TimedeltaIndex * Series[int] issue mentioned above is still outstanding. Update Just opened #19042 for the multiplication issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

2 participants