Skip to content

REF: Period check compatabile with #24285

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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ def wrapper(self, other):
other = other._values

if isinstance(other, Period):
if other.freq != self.freq:
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
raise IncompatibleFrequency(msg)
self._check_compatible_with(other)

result = op(other.ordinal)
elif isinstance(other, cls):
if other.freq != self.freq:
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
raise IncompatibleFrequency(msg)
self._check_compatible_with(other)

if not_implemented:
return NotImplemented
Expand Down Expand Up @@ -241,6 +237,11 @@ def _generate_range(cls, start, end, periods, freq, fields):

return subarr, freq

def _check_compatible_with(self, other):
if self.freqstr != other.freqstr:
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
raise IncompatibleFrequency(msg)

# --------------------------------------------------------------------
# Data / Attributes

Expand Down Expand Up @@ -395,10 +396,7 @@ def _validate_fill_value(self, fill_value):
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, Period):
if fill_value.freq != self.freq:
msg = DIFFERENT_FREQ_INDEX.format(self.freq.freqstr,
fill_value.freqstr)
raise IncompatibleFrequency(msg)
self._check_compatible_with(fill_value)
fill_value = fill_value.ordinal
else:
raise ValueError("'fill_value' should be a Period. "
Expand Down Expand Up @@ -667,10 +665,7 @@ def _sub_datelike(self, other):
def _sub_period(self, other):
# If the operation is well-defined, we return an object-Index
# of DateOffsets. Null entries are filled with pd.NaT
if self.freq != other.freq:
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
raise IncompatibleFrequency(msg)

self._check_compatible_with(other)
asi8 = self.asi8
new_data = asi8 - other.ordinal
new_data = np.array([self.freq * x for x in new_data])
Expand Down