8000 BUG: Fix PeriodIndex +/- TimedeltaIndex by jbrockmendel · Pull Request #23031 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix PeriodIndex +/- TimedeltaIndex #23031

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 14 commits into from
Oct 15, 2018
Merged
Prev Previous commit
Next Next commit
docstring
  • Loading branch information
jbrockmendel committed Oct 14, 2018
commit eb252bff0e8f12a228477d7cae507c538cd0abc5
19 changes: 19 additions & 0 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,25 @@ def _maybe_convert_timedelta(self, other):
freqstr=self.freqstr))

def _check_timedeltalike_freq_compat(self, other):
"""
Arithmetic operations with timedelta-like scalars or array `other`
are only valid if `other` is an integer multiple of `self.freq`.
If the operation is valid, find that integer multiple. Otherwise,
raise because the operation is invalid.

Parameters
----------
other : timedelta, np.timedelta64, Tick,
ndarray[timedelta64], TimedeltaArray, TimedeltaIndex

Returns
-------
multiple : int or ndarray[int64]

Raises
------
IncompatibleFrequency
"""
assert isinstance(self.freq, Tick) # checked by calling function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add a doc string here

own_offset = frequencies.to_offset(self.freq.rule_code)
base_nanos = delta_to_nanoseconds(own_offset)
Expand Down
0