Skip to content

Commit 606d1c5

Browse files
KhemkaranKhemkaran
authored andcommitted
modified unique() in interval.py to handle object case
1 parent 8f05f9f commit 606d1c5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pandas/core/arrays/interval.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,13 +1992,18 @@ def _from_combined(self, combined: np.ndarray) -> IntervalArray:
19921992
def unique(self) -> IntervalArray:
19931993
# Using .view("complex128") with negatives causes issues. # GH#61917
19941994
combined = self._combined
1995-
if not combined.flags.c_contiguous:
1996-
combined = np.ascontiguousarray(combined)
1997-
structured = combined.view(
1998-
[("left", combined.dtype), ("right", combined.dtype)]
1999-
)[:, 0]
2000-
unique_structured = unique(structured)
2001-
nc = unique_structured.view(combined.dtype)
1995+
combined = np.ascontiguousarray(combined)
1996+
if combined.dtype == np.object_:
1997+
nc = unique(
1998+
self._combined.view("complex128")[:, 0] # type: ignore[call-overload]
1999+
)
2000+
nc = nc[:, None]
2001+
else:
2002+
structured = combined.view(
2003+
[("left", combined.dtype), ("right", combined.dtype)]
2004+
)[:, 0]
2005+
unique_structured = unique(structured)
2006+
nc = unique_structured.view(combined.dtype)
20022007
return self._from_combined(nc)
20032008

20042009

0 commit comments

Comments
 (0)