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

DEPR: DatetimeIndex/PeriodsIndex +/- ops (GH9094) #9630

Merged
merged 1 commit into from
Mar 11, 2015

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Mar 11, 2015

closes #9094
closes #9095

deprecate DatetimeIndex/PeriodIndex +/- ops which are set ops. In a future version - will produce a TimeDeltaIndex and + a TypeError

@jreback jreback added the Deprecate Functionality to remove in pandas label Mar 11, 2015
@jreback jreback added this to the 0.16.0 milestone Mar 11, 2015
@jreback
Copy link
Contributor Author

jreback commented Mar 11, 2015

surprise surprise, this was not actually tested anywhere AT ALL.

@jreback jreback force-pushed the dti_sub branch 2 times, most recently from 722a124 to 4d1ca4f Compare March 11, 2015 01:58
@jorisvandenbossche
Copy link
Member

Should the same be done for the other operations?

Eg addition also still does a set operation:

In [12]: dti + dti
Out[12]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01, 2012-01-02]
Length: 2, Freq: D, Timezone: None

Addition is not a usefull operation for datetimes as a numeric operation, but better to be consistent in the fact it will not be a set operation in the future I think.

@jreback
Copy link
Contributor Author

jreback commented Mar 11, 2015

@jorisvandenbossche yes, dti + dti should be a TypeError (in 0.17.0) to be consistent. (as is dti + dt now). will update.

@jorisvandenbossche
Copy link
Member

This should then also close #9095 I think.

@jreback
Copy link
Contributor Author

jreback commented Mar 11, 2015

hmm, I guess we changed these all to NotImplementedError (which is actually more correct). but most are still TypeErrors...hmm

In [3]: pd.date_range('20130101',periods=5)+Timestamp('20140101')
NotImplementedError: 
In [4]: pd.date_range('20130101',periods=5)+Timestamp('20140101').to_datetime64()

TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]')

@shoyer IIRC did you change these? (I know you suggested we did....)

@jreback jreback changed the title DEPR: deprecate DatetimeIndex - DatetimeIndex (subtraction) (GH9094) DEPR: DatetimeIndex +/- DatetimeIndex ops (GH9094) Mar 11, 2015
@jreback jreback changed the title DEPR: DatetimeIndex +/- DatetimeIndex ops (GH9094) DEPR: DatetimeIndex/PeriodsIndex +/- ops (GH9094) Mar 11, 2015
@shoyer
Copy link
Member

shoyer commented Mar 11, 2015

NotImplementedError is wrong -- pd.date_range('20130101',periods=5)+Timestamp('20140101') should be a TypeError.

I believe I suggested changing some operations like __add__ to return NotImplemented, but that's not NotImplementedError and it's something that the user should never see -- Python should translate it into a TypeError before it reaches the user.

@jreback
Copy link
Contributor Author

jreback commented Mar 11, 2015

@shoyer yeh I just looked at the code and everything is tested as a TypeError, so maybe this odd that it is showing up like this.

@jorisvandenbossche
Copy link
Member

I think this is implemented as an NotImplementedError, because this is within DatetimeIndexOpsMixin its method _add_datelike, and this method should be overwritten in DatetimeIndex? (because this should work for TimedeltaIndex)?

And indeed, in TimedeltaIndex it is overwritten (https://github.com/pydata/pandas/blob/899212982af5978a5991dfd9517f3a0212bcdaa8/pandas/tseries/tdi.py#L316), but not in DatetimeIndex

      this currently represents a set difference operation and should actually
      be DTI subtraction to yield a TimeDeltaIndex. Change in a future version.
jreback added a commit that referenced this pull request Mar 11, 2015
DEPR: DatetimeIndex/PeriodsIndex +/- ops (GH9094)
@jreback jreback merged commit 28b5ef9 into pandas-dev:master Mar 11, 2015
jorisvandenbossche added a commit that referenced this pull request Sep 7, 2016
…#14164)

API/DEPR: Remove +/- as setops for DatetimeIndex/PeriodIndex (GH9630)

xref #13777, deprecations put in place in #9630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v0.15.1 breaks index set operations API: datetimeindex subtraction
3 participants