-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Make pd.Period immutable #17239
Make pd.Period immutable #17239
Changes from 13 commits
89cf9d6
e6ca02c
8912283
d33922f
b86a7b9
1c6f197
08a218c
2642366
6c461eb
0e62865
cd687bf
dc2111c
1e92344
19567c8
f739f8f
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 |
---|---|---|
|
@@ -138,6 +138,14 @@ Backwards incompatible API changes | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
||
.. _whatsnew_0210.api_breaking.Period: | ||
|
||
pd.Period objects are now immutable | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
:class:`Period` will now raise an ``AttributeError`` when a user tries to assign a new value to the `ordinal` or `freq` attributes (:issue:`17116`). | ||
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. no what I meant was remove this as a sub-section and just add it as a single like in other breaking changes. 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. All the other breaking changes have a subsection like:
I'll keep pushing guesses until the Infinite Monkeys Theorem kicks in. 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. Still not fully what he meant :-) The "Backwards incompatible API changes" section starts with subsections for things that we think are important enough to explain in more than a single line, and at the end there is section "other API changes" with a bunch of single entries: So you can put it there. |
||
|
||
|
||
.. _whatsnew_0210.api_breaking.deps: | ||
|
||
Dependencies have increased minimum versions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,9 @@ from datetime cimport ( | |
PANDAS_FR_ns, | ||
INT32_MIN) | ||
|
||
|
||
cimport util, lib | ||
|
||
from lib cimport is_null_datetimelike, is_period | ||
from pandas._libs import tslib, lib | ||
from pandas._libs.tslib import (Timedelta, Timestamp, iNaT, | ||
|
@@ -668,13 +670,17 @@ class IncompatibleFrequency(ValueError): | |
|
||
cdef class _Period(object): | ||
|
||
cdef public: | ||
cdef readonly: | ||
int64_t ordinal | ||
object freq | ||
|
||
_comparables = ['name', 'freqstr'] | ||
_typ = 'period' | ||
|
||
def __cinit__(self, ordinal, freq): | ||
self.ordinal = ordinal | ||
self.freq = freq | ||
|
||
@classmethod | ||
def _maybe_convert_freq(cls, object freq): | ||
|
||
|
@@ -698,9 +704,8 @@ cdef class _Period(object): | |
if ordinal == iNaT: | ||
return NaT | ||
else: | ||
self = _Period.__new__(cls) | ||
self.ordinal = ordinal | ||
self.freq = cls._maybe_convert_freq(freq) | ||
freq = cls._maybe_convert_freq(freq) | ||
self = _Period.__new__(cls, ordinal, freq) | ||
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 this be 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. I don't think so. |
||
return self | ||
|
||
def __richcmp__(self, other, op): | ||
|
@@ -752,7 +757,7 @@ cdef class _Period(object): | |
def __add__(self, other): | ||
if isinstance(self, Period): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.Tick, offsets.DateOffset, | ||
offsets.DateOffset, | ||
Timedelta)): | ||
return self._add_delta(other) | ||
elif other is NaT: | ||
|
@@ -770,7 +775,7 @@ cdef class _Period(object): | |
def __sub__(self, other): | ||
if isinstance(self, Period): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.Tick, offsets.DateOffset, | ||
offsets.DateOffset, | ||
Timedelta)): | ||
neg_other = -other | ||
return self + neg_other | ||
|
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.
just say Period