-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: deprecate integer add/sub with DTI/TDI/PI/Timestamp/Period #22535
Changes from 1 commit
145eb6a
d5c5f28
3fb29bc
81c9eab
26c9966
11959b1
8952cb5
7c79364
d0fa41a
c23346b
f6daf34
b7e3dcf
2a829d3
f24643c
6fea2a8
b469bef
20d58fa
984bc7e
841718c
7e7a348
17f6be0
29cca46
b0a222a
14b9eaf
55dc265
9443df9
d46452d
af31b0c
0bebbe0
c7dd7ce
ca55b4a
394a3b8
3884bb4
a15d9e4
5256671
d8865d7
da72660
fcd65b3
6ded8b1
4a7b589
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -514,6 +514,8 @@ Deprecations | |
- The signature of :meth:`Series.to_csv` has been uniformed to that of doc:meth:`DataFrame.to_csv`: the name of the first argument is now 'path_or_buf', the order of subsequent arguments has changed, the 'header' argument now defaults to True. (:issue:`19715`) | ||
- :meth:`Categorical.from_codes` has deprecated providing float values for the ``codes`` argument. (:issue:`21767`) | ||
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`) | ||
- Addition or subtraction of integers with :class:`Timestamp`, :class:`Period`, :class:`DatetimeIndex`, :class:`TimedeltaIndex`, :class:`PeriodIndex` is deprecated, will be removed in a future version (:issue:`21939`) | ||
- Addition or subtraction of integer-dtyped arrays with:class:`DatetimeIndex`, :class:`TimedeltaIndex`, :class:`PeriodIndex` is deprecated, will be removed in a future version (:issue:`21939`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after with |
||
|
||
.. _whatsnew_0240.prior_deprecations: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import datetime, date | ||
import warnings | ||
|
||
from cpython cimport ( | ||
PyUnicode_Check, | ||
|
@@ -1645,6 +1646,14 @@ cdef class _Period(object): | |
elif other is NaT: | ||
return NaT | ||
elif util.is_integer_object(other): | ||
warnings.warn("Addition of integers to {cls} is " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you call a function for this warning (not sure exatcly where), rather than repeating each time, prob need to pass in the level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you have in mind. Just a one-liner containing this warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah a module level function just seems better than copy-pasting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you do this |
||
"deprecated, will be removed in version " | ||
"0.26.0 (or 1.0, whichever comes first). " | ||
"Instead of adding `n`, add " | ||
"`n * self.freq`" | ||
.format(cls=type(self).__name__), | ||
FutureWarning) | ||
|
||
ordinal = self.ordinal + other * self.freq.n | ||
return Period(ordinal=ordinal, freq=self.freq) | ||
elif (PyDateTime_Check(other) or | ||
|
@@ -1671,6 +1680,14 @@ cdef class _Period(object): | |
neg_other = -other | ||
return self + neg_other | ||
elif util.is_integer_object(other): | ||
warnings.warn("Subtraction of integers from {cls} is " | ||
"deprecated, will be removed in version " | ||
"0.26.0 (or 1.0, whichever comes first). " | ||
"Instead of subtracting `n`, subtract " | ||
"`n * self.freq`" | ||
.format(cls=type(self).__name__), | ||
FutureWarning) | ||
|
||
ordinal = self.ordinal - other * self.freq.n | ||
return Period(ordinal=ordinal, freq=self.freq) | ||
elif is_period_object(other): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,14 +250,24 @@ cdef class _Timestamp(datetime): | |
return np.datetime64(self.value, 'ns') | ||
|
||
def __add__(self, other): | ||
cdef int64_t other_int, nanos | ||
cdef: | ||
int64_t other_int, nanos | ||
|
||
if is_timedelta64_object(other): | ||
other_int = other.astype('timedelta64[ns]').view('i8') | ||
return Timestamp(self.value + other_int, | ||
tz=self.tzinfo, freq=self.freq) | ||
|
||
elif is_integer_object(other): | ||
if self.freq is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it necessary for freq to be none here? (we don't have this check elsewhere) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be not-None, good catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be changed? |
||
warnings.warn("Addition of integers to {cls} is " | ||
"deprecated, will be removed in version " | ||
"0.26.0 (or 1.0, whichever comes first). " | ||
"Instead of adding `n`, add " | ||
"`n * self.freq`" | ||
.format(cls=type(self).__name__), | ||
FutureWarning) | ||
|
||
if self is NaT: | ||
# to be compat with Period | ||
return NaT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls make a sub-section and show what is being deprecated and what is the alternative. this is actually a rather large change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to get to this tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback just added this section; wasn't sure on where in the doc to put it and the ipython/code-block syntax is a shot in the dark. Please advise.