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

API: datetimeindex subtraction #9094

Closed
jreback opened this issue Dec 16, 2014 · 14 comments · Fixed by #9630
Closed

API: datetimeindex subtraction #9094

jreback opened this issue Dec 16, 2014 · 14 comments · Fixed by #9630
Labels
API Design Datetime Datetime data dtype Timedelta Timedelta data type
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Dec 16, 2014

from SO and previous discussions

currently you cannot subtract 2 datetimeindexes ('-' is actually a set op). This is the ONLY valid numerical type of operation (e.g. you cannot add dti).

We current support pretty much the fully gamut of obvious ops, with dti-dti being the exception.

full list of tests are here: https://github.com/pydata/pandas/blob/master/pandas/tseries/tests/test_base.py#L434

I will propose

dti.sub(dti) to rectify this

thoughts

@jreback jreback added Datetime Datetime data dtype API Design Timedelta Timedelta data type labels Dec 16, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 16, 2014
@jorisvandenbossche
Copy link
Member

We have deprecated the set ops on the index using - and + (#8227, #8226), so in the future, when this deprecation has been put in practice, we can use - for subtraction.
But for now, as long using - is not possible, adding dti.sub(dti) seems like a good idea to me.

Are there actually other reasons one would want to use a sub method instead of -? (because that would be a reason to also add add/multiply/... as for Series)

Then on the naming, is there a reason you have for Sereis both sub and subtract? (and also both mult/multiply, div/divide, ..)

@jreback
Copy link
Contributor Author

jreback commented Dec 16, 2014

@jorisvandenbossche the deprecations don't apply to either Numeric, Datetime, Period, or Timedelta index (IOW, ONLY to Index itself).

So dti-dti is a set op. This is NOT deprecated. It could be changed (and maybe should be?)

@jreback
Copy link
Contributor Author

jreback commented Dec 16, 2014

hmm, maybe we should deprecate and do the subtraction.

In [1]: dti = pd.date_range('20130101',periods=3)

In [2]: dti-dti
Out[2]: Index([], dtype='object')

In [3]: dti.difference(dti)
Out[3]: Index([], dtype='object')

@jorisvandenbossche
Copy link
Member

@jreback Ah, yes, if we agree on the deprecation of -/+ as index ops, then that should be for all Index subclasses, not only for Index itself, otherwise it is not really usefull

@jreback
Copy link
Contributor Author

jreback commented Dec 16, 2014

ok then i will change DatetimeIndex in 0.16 then to do direct subtraction - makes more sense
(actually pretty easy to 'warn' on the older operation as the index have to be the same length)

@jorisvandenbossche
Copy link
Member

@jreback I think that is too early for such an api change IMO. But see also #9095 I just opened

@shoyer
Copy link
Member

shoyer commented Dec 17, 2014

I really thought we had deprecated -/+ as index ops on all Index types, though I guess we are not currently issuing a warning for these operations (the docs are more ambiguous).

@jreback
Copy link
Contributor Author

jreback commented Dec 17, 2014

as I commented on the other issue. This is an anomaly and should be fixed (for PeriodIndex) as well. I don't think waiting ANOTHER big release cycle is warranted.

@jorisvandenbossche
Copy link
Member

This is with the latest release 0.15.2:

In [1]: dti = pd.date_range('2012-01-01', periods=2)

In [2]: dti - dti
Out[2]: Index([], dtype='object')

In [3]: pd.__version__
Out[3]: '0.15.2'

This is doing a set operation, without a deprecation warning.
So IMO we should not change the behaviour straight away, but first raise a deprecation warning.

@jreback
Copy link
Contributor Author

jreback commented Dec 17, 2014

the warning prob should have been there in 0.15

so we'll call this an api change then

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jorisvandenbossche
Copy link
Member

@jreback I think we should revisit this for 0.16 (or at least the deprecation)

We do want to be able to do numeric operations, so we should deprecate the set operation (in theory this was already deprecated in 0.15, but for datimeindexes, there was not deprecation warning raised)

on master:

In [6]: dti = pd.date_range('2012-01-01', periods=2)

In [7]: dti - dti
Out[7]: Index([], dtype='object')

@jreback
Copy link
Contributor Author

jreback commented Mar 11, 2015

yes could deprecate the actual subtraction op (which is the only thing left) on dti - dti for 0.16
(as .difference is the way to go)

@jreback
Copy link
Contributor Author

jreback commented Sep 13, 2016

@jorisvandenbossche this is in 0.19.0rc1 right? (need to check the issue)

@jorisvandenbossche
Copy link
Member

Yes, indeed, but this issue was in the end for raising the deprecation warning, so I didn't reference it from the PR (but is could be referenced). PR that changed the setop to timedelta is #14164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants