diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 324daff6f0b1c..e73a4348eece1 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -360,7 +360,7 @@ I/O Period ^^^^^^ -- +- Bug in subtraction of :class:`Period` from :class:`PeriodArray` returning wrong results (:issue:`45999`) - Plotting diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 04cc70b7efa6a..6189584dff7f1 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -710,7 +710,7 @@ def _sub_period(self, other): 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]) + new_data = np.array([self.freq.base * x for x in new_data]) if self._hasna: new_data[self._isnan] = NaT diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index bbb464cb7dfed..06b372abf66f5 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -25,9 +25,9 @@ from pandas.tests.extension import base -@pytest.fixture -def dtype(): - return PeriodDtype(freq="D") +@pytest.fixture(params=["D", "2D"]) +def dtype(request): + return PeriodDtype(freq=request.param) @pytest.fixture