Skip to content

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

Closed
wants to merge 7 commits into from

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@pep8speaks
Copy link

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):
Copy link
Member Author

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__))

Copy link
Member Author

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
Copy link
Member Author

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)
Copy link
Member Author

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

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')
Copy link
Member Author

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):
Copy link
Member Author

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.

@jbrockmendel jbrockmendel deleted the dlike_dedup2 branch April 5, 2020 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants