From bf97db36b5e6faa5896b70f43d01483095601828 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Wed, 16 Feb 2022 14:35:33 +0100 Subject: [PATCH] BUG: PeriodArray subtraction returning wrong results (#46006) --- doc/source/whatsnew/v1.5.0.rst | 2 +- pandas/core/arrays/period.py | 2 +- pandas/tests/extension/test_period.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) 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