@@ -1932,16 +1932,16 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:
1932
1932
if self .dtype == values .dtype :
1933
1933
# GH#38353 instead of casting to object, operating on a
1934
1934
# complex128 ndarray is much more performant.
1935
- left = self ._combined . view ( "complex128" )
1936
- right = values ._combined . view ( "complex128" )
1935
+ left = self ._combined
1936
+ right = values ._combined
1937
1937
# error: Argument 1 to "isin" has incompatible type
1938
1938
# "Union[ExtensionArray, ndarray[Any, Any],
1939
1939
# ndarray[Any, dtype[Any]]]"; expected
1940
1940
# "Union[_SupportsArray[dtype[Any]],
1941
1941
# _NestedSequence[_SupportsArray[dtype[Any]]], bool,
1942
1942
# int, float, complex, str, bytes, _NestedSequence[
1943
1943
# Union[bool, int, float, complex, str, bytes]]]"
1944
- return np .isin (left , right ).ravel () # type: ignore[arg-type]
1944
+ return np .isin (left , right ).ravel ()
1945
1945
1946
1946
elif needs_i8_conversion (self .left .dtype ) ^ needs_i8_conversion (
1947
1947
values .left .dtype
@@ -1963,8 +1963,11 @@ def _combined(self) -> IntervalSide:
1963
1963
comb = left ._concat_same_type ( # type: ignore[union-attr]
1964
1964
[left , right ], axis = 1
1965
1965
)
1966
+ comb = comb .view ("complex128" )[:, 0 ]
1966
1967
else :
1967
- comb = np .concatenate ([left , right ], axis = 1 )
1968
+ comb = (np .array (left .ravel (), dtype = complex )) + (
1969
+ 1j * np .array (right .ravel (), dtype = complex )
1970
+ )
1968
1971
return comb
1969
1972
1970
1973
def _from_combined (self , combined : np .ndarray ) -> IntervalArray :
@@ -1985,27 +1988,14 @@ def _from_combined(self, combined: np.ndarray) -> IntervalArray:
1985
1988
)._from_sequence (nc [:, 1 ], dtype = dtype )
1986
1989
else :
1987
1990
assert isinstance (dtype , np .dtype )
1988
- nc = np .hstack (
1989
- [np .real (combined ).astype (dtype ), np .imag (combined ).astype (dtype )]
1990
- ).reshape (- 1 , 2 )
1991
- new_left = nc [:, 0 ].view (dtype )
1992
- new_right = nc [:, 1 ].view (dtype )
1991
+ new_left = np .real (combined ).astype (dtype ).ravel ()
1992
+ new_right = np .imag (combined ).astype (dtype ).ravel ()
1993
1993
return self ._shallow_copy (left = new_left , right = new_right )
1994
1994
1995
1995
def unique (self ) -> IntervalArray :
1996
1996
# No overload variant of "__getitem__" of "ExtensionArray" matches argument
1997
1997
# type "Tuple[slice, int]"
1998
- if needs_i8_conversion (self ._left .dtype ):
1999
- nc = unique (
2000
- self ._combined .view ("complex128" )[:, 0 ] # type: ignore[call-overload]
2001
- )
2002
- else :
2003
- nc = unique (
2004
- # Using .view("complex128") with negatives causes issues.
2005
- # GH#61917
2006
- (np .array (self ._combined [:, 0 ], dtype = complex ))
2007
- + (1j * np .array (self ._combined [:, 1 ], dtype = complex ))
2008
- )
1998
+ nc = unique (self ._combined )
2009
1999
nc = nc [:, None ]
2010
2000
return self ._from_combined (nc )
2011
2001
0 commit comments