-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Use ._tshift internally for datetimelike ops #22949
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,7 +455,7 @@ def _sub_period_array(self, other): | |
def _addsub_int_array(self, other, op): | ||
""" | ||
Add or subtract array-like of integers equivalent to applying | ||
`shift` pointwise. | ||
`_tshift` pointwise. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -553,6 +553,23 @@ def shift(self, periods, freq=None): | |
-------- | ||
Index.shift : Shift values of Index. | ||
""" | ||
return self._tshift(periods=periods, freq=freq) | ||
|
||
def _tshift(self, periods, freq=None): | ||
""" | ||
Shift each value by `periods`. | ||
|
||
Note this is different from ExtensionArray.shift, which | ||
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. how is this relevant here? this is simply a re-definition of what shift means. I understand the desire to make things clear, but this has always been the case, for example in comparing a DTI to an Index. |
||
shifts the *position* of each element, padding the end with | ||
missing values. | ||
|
||
Parameters | ||
---------- | ||
periods : int | ||
Number of periods to shift by. | ||
freq : pandas.DateOffset, pandas.Timedelta, or string | ||
Frequency increment to shift by. | ||
""" | ||
if freq is not None and freq != self.freq: | ||
if isinstance(freq, compat.string_types): | ||
freq = frequencies.to_offset(freq) | ||
|
@@ -600,7 +617,7 @@ def __add__(self, other): | |
elif lib.is_integer(other): | ||
# This check must come after the check for np.timedelta64 | ||
# as is_integer returns True for these | ||
result = self.shift(other) | ||
result = self._tshift(other) | ||
|
||
# array-like others | ||
elif is_timedelta64_dtype(other): | ||
|
@@ -652,7 +669,7 @@ def __sub__(self, other): | |
elif lib.is_integer(other): | ||
# This check must come after the check for np.timedelta64 | ||
# as is_integer returns True for these | ||
result = self.shift(-other) | ||
result = self._tshift(-other) | ||
elif isinstance(other, Period): | ||
result = self._sub_period(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.
why don't we call this ._time_shift or ._period_shift
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.
if you are actually going to change this, then this should be much more consistent across the code base, e.g. does internals need changing, what about the Index classes?
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 chose
_tshift
to match Series.tshift, which has the same behavior, but for the Series' index.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.
we have a note to deprecate tshift entirely. I don't think this is a good name at all.