Skip to content

Commit bf97db3

Browse files
authored
BUG: PeriodArray subtraction returning wrong results (#46006)
1 parent d633abd commit bf97db3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

doc/source/whatsnew/v1.5.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ I/O
360360

361361
Period
362362
^^^^^^
363-
-
363+
- Bug in subtraction of :class:`Period` from :class:`PeriodArray` returning wrong results (:issue:`45999`)
364364
-
365365

366366
Plotting

pandas/core/arrays/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def _sub_period(self, other):
710710
self._check_compatible_with(other)
711711
asi8 = self.asi8
712712
new_data = asi8 - other.ordinal
713-
new_data = np.array([self.freq * x for x in new_data])
713+
new_data = np.array([self.freq.base * x for x in new_data])
714714

715715
if self._hasna:
716716
new_data[self._isnan] = NaT

pandas/tests/extension/test_period.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
from pandas.tests.extension import base
2626

2727

28-
@pytest.fixture
29-
def dtype():
30-
return PeriodDtype(freq="D")
28+
@pytest.fixture(params=["D", "2D"])
29+
def dtype(request):
30+
return PeriodDtype(freq=request.param)
3131

3232

3333
@pytest.fixture

0 commit comments

Comments
 (0)