Skip to content

Commit c301882

Browse files
committed
BUG: fix incorrect difference result of periodindex with index
1 parent 48b1571 commit c301882

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/core/indexes/period.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,22 @@ def shift(self, periods: int = 1, freq=None) -> Self:
534534
)
535535
return self + periods
536536

537+
def _convert_can_do_setop(self, other):
538+
try:
539+
if isinstance(other, Index):
540+
# Handle empty cases
541+
if other.empty:
542+
return super()._convert_can_do_setop(other)
543+
544+
# Convert non-PeriodIndex to PeriodIndex
545+
if not isinstance(other, PeriodIndex):
546+
other = PeriodIndex(other, freq=self.freq)
547+
548+
except (TypeError, ValueError):
549+
return super()._convert_can_do_setop(other)
550+
551+
return super()._convert_can_do_setop(other)
552+
537553

538554
def period_range(
539555
start=None,

0 commit comments

Comments
 (0)