-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative #61920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative #61920
Changes from 15 commits
deea1a0
8f05f9f
606d1c5
e8a7607
843539c
eae020c
3547d84
9be72c7
fce684f
d541aac
b919b7e
8b0fc27
f9ee346
2dda75a
3b7552b
6877e68
3302239
880ee51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2079,16 +2079,9 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]: | |
if self.dtype == values.dtype: | ||
# GH#38353 instead of casting to object, operating on a | ||
# complex128 ndarray is much more performant. | ||
left = self._combined.view("complex128") | ||
right = values._combined.view("complex128") | ||
# error: Argument 1 to "isin" has incompatible type | ||
# "Union[ExtensionArray, ndarray[Any, Any], | ||
# ndarray[Any, dtype[Any]]]"; expected | ||
# "Union[_SupportsArray[dtype[Any]], | ||
# _NestedSequence[_SupportsArray[dtype[Any]]], bool, | ||
# int, float, complex, str, bytes, _NestedSequence[ | ||
# Union[bool, int, float, complex, str, bytes]]]" | ||
return np.isin(left, right).ravel() # type: ignore[arg-type] | ||
left = self._combined | ||
right = values._combined | ||
return np.isin(left, right).ravel() | ||
|
||
elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion( | ||
values.left.dtype | ||
|
@@ -2110,18 +2103,21 @@ def _combined(self) -> IntervalSide: | |
comb = left._concat_same_type( # type: ignore[union-attr] | ||
[left, right], axis=1 | ||
) | ||
comb = comb.view("complex128")[:, 0] | ||
else: | ||
comb = np.concatenate([left, right], axis=1) | ||
comb = (np.array(left.ravel(), dtype="complex128")) + ( | ||
1j * np.array(right.ravel(), dtype="complex128") | ||
) | ||
return comb | ||
|
||
def _from_combined(self, combined: np.ndarray) -> IntervalArray: | ||
""" | ||
Create a new IntervalArray with our dtype from a 1D complex128 ndarray. | ||
""" | ||
nc = combined.view("i8").reshape(-1, 2) | ||
|
||
dtype = self._left.dtype | ||
if needs_i8_conversion(dtype): | ||
nc = combined.view("i8").reshape(-1, 2) | ||
assert isinstance(self._left, (DatetimeArray, TimedeltaArray)) | ||
new_left: DatetimeArray | TimedeltaArray | np.ndarray = type( | ||
self._left | ||
|
@@ -2132,16 +2128,15 @@ def _from_combined(self, combined: np.ndarray) -> IntervalArray: | |
)._from_sequence(nc[:, 1], dtype=dtype) | ||
else: | ||
assert isinstance(dtype, np.dtype) | ||
new_left = nc[:, 0].view(dtype) | ||
new_right = nc[:, 1].view(dtype) | ||
new_left = np.real(combined).astype(dtype).ravel() | ||
new_right = np.imag(combined).astype(dtype).ravel() | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self._shallow_copy(left=new_left, right=new_right) | ||
|
||
def unique(self) -> IntervalArray: | ||
# No overload variant of "__getitem__" of "ExtensionArray" matches argument | ||
# type "Tuple[slice, int]" | ||
nc = unique( | ||
self._combined.view("complex128")[:, 0] # type: ignore[call-overload] | ||
) | ||
nc = unique(self._combined) | ||
khemkaran10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Ensure nc is a numpy array for _from_combined | ||
if not isinstance(nc, np.ndarray): | ||
nc = np.asarray(nc) | ||
|
||
nc = nc[:, None] | ||
return self._from_combined(nc) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.