def wrapper(self, other): if isinstance(other, Period): func = getattr(self.values, opname) other_base, _ = _gfc(other.freq) if other.freq != self.freq: msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr) raise IncompatibleFrequency(msg) result = func(other.ordinal) elif isinstance(other, PeriodIndex): if other.freq != self.freq: msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr) raise IncompatibleFrequency(msg) result = getattr(self.values, opname)(other.values) mask = (missing.mask_missing(self.values, tslib.iNaT) | missing.mask_missing(other.values, tslib.iNaT)) if mask.any(): result[mask] = nat_result return result else: other = Period(other, freq=self.freq) func = getattr(self.values, opname) result = func(other.ordinal) if other.ordinal == tslib.iNaT: result.fill(nat_result) mask = self.values == tslib.iNaT if mask.any(): result[mask] = nat_result return result