-
- Notifications
You must be signed in to change notification settings - Fork 19.3k
Make pd.Period immutable #17239
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
Merged
Merged
Make pd.Period immutable #17239
Changes from 14 commits
Commits
Show all changes
15 commits Select commit Hold shift + click to select a range
89cf9d6 Make Period ordinal and freq readonly
jbrockmendel e6ca02c Tests for Period immutability
jbrockmendel 8912283 Trim whitespace
jbrockmendel d33922f flake8 whitespace fixup
jbrockmendel b86a7b9 Add note in whatsnew; address reviewer requests
jbrockmendel 1c6f197 flake8 whitespace fixup
jbrockmendel 08a218c Merge branch 'master' into period_immutable
jbrockmendel 2642366 More brevity
jbrockmendel 6c461eb Merge branch 'period_immutable' of https://github.com/jbrockmendel/pa…
jbrockmendel 0e62865 Merge branch 'master' into period_immutable
jbrockmendel cd687bf Remove message per reviewer suggestion
jbrockmendel dc2111c unwrap line per reviewer request
jbrockmendel 1e92344 Merge branch 'period_immutable' of https://github.com/jbrockmendel/pa…
jbrockmendel 19567c8 Try to guess what jreback wants
jbrockmendel f739f8f move whatsnew to correct location
jreback File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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) | ||
| Contributor 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 Member Author 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 | ||
| | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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:
https://github.com/jbrockmendel/pandas/blob/19567c8f0de212dec15e17dc918e6eada6a8c354/doc/source/whatsnew/v0.21.0.txt#L280-L295
So you can put it there.