-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: De-duplicate pieces of datetimelike arithmetic #23166
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
Conversation
Hello @jbrockmendel! Thanks for submitting the PR.
|
@@ -246,27 +246,6 @@ def _maybe_mask_results(self, result, fill_value=None, convert=None): | |||
result[self._isnan] = fill_value | |||
return result | |||
|
|||
def _nat_new(self, box=True): |
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.
Only used once outside of tests; less verbose to do inline.
raise TypeError("{cls} subtraction must have the same " | ||
"timezones or no timezones" | ||
.format(cls=type(self).__name__)) | ||
|
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.
The casting and timezone checking used to be done inside the calling function. Cleaner to do it here.
new_values = self._add_delta_tdi(delta) | ||
else: | ||
new_values = self.astype('O') + delta |
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.
not reachable
if isinstance(delta, (Tick, timedelta, np.timedelta64)): | ||
new_values = self._add_delta_td(delta) | ||
elif is_timedelta64_dtype(delta): | ||
if not isinstance(delta, TimedeltaArrayMixin): | ||
delta = TimedeltaArrayMixin(delta) |
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.
do this inside add_delta_dti
pandas/core/arrays/datetimes.py
Outdated
if self.tz is not None and self.tz is not utc: | ||
result = result.tz_convert(self.tz) | ||
return result | ||
return type(self)(new_values, tz=self.tz, freq='infer') |
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.
Is the more complicated construction above necessary for some reason? AFAICT these are equivalent.
@@ -445,48 +442,6 @@ def _time_shift(self, n): | |||
values[self._isnan] = iNaT | |||
return self._shallow_copy(values=values) | |||
|
|||
def _maybe_convert_timedelta(self, 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.
Since #23031 this is no longer used by the Array class; moved back to the Index class.
git diff upstream/master -u -- "*.py" | flake8 --diff