Skip to content

Commit 4d0c9b5

Browse files
committed
fix casting
1 parent ba27811 commit 4d0c9b5

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

pandas/core/indexes/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6209,12 +6209,6 @@ def _maybe_downcast_for_indexing(self, other: Index) -> tuple[Index, Index]:
62096209
# let's instead try with a straight Index
62106210
self = Index(self._values)
62116211

6212-
elif self.inferred_type == "string" and isinstance(other, ABCPeriodIndex):
6213-
try:
6214-
return self.astype(other.dtype), other
6215-
except (TypeError, ValueError):
6216-
return self, other
6217-
62186212
if not is_object_dtype(self.dtype) and is_object_dtype(other.dtype):
62196213
# Reverse op so we dont need to re-implement on the subclasses
62206214
other, self = other._maybe_downcast_for_indexing(self)

pandas/core/indexes/period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ def shift(self, periods: int = 1, freq=None) -> Self:
515515
return self + periods
516516

517517
def _difference(self, other, sort=None) -> PeriodIndex:
518-
if not isinstance(other, PeriodIndex):
519-
self, other = self._maybe_downcast_for_indexing(other)
518+
if isinstance(other, Index) and other.inferred_type == "string":
519+
other = other.astype(self.dtype)
520520

521521
return super()._difference(other, sort=sort)
522522

0 commit comments

Comments
 (0)