-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
Open
khemkaran10
wants to merge
20
commits into
pandas-dev:main
Choose a base branch
from
khemkaran10:issue_61917
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative #61920
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
deea1a0
Fix issue 61917, modified uniqe() func in interval.py
8f05f9f
Merge remote-tracking branch 'upstream/main' into issue_61917
606d1c5
modified unique() in interval.py to handle object case
e8a7607
:x
843539c
Merge remote-tracking branch 'upstream/main' into issue_61917
eae020c
modified unique() function in arrays/interval.py
3547d84
Merge remote-tracking branch 'upstream/main' into issue_61917
9be72c7
make changes to unique() in interval.py
fce684f
added complex array creation logic in _combined directly
d541aac
Merge remote-tracking branch 'upstream/main' into issue_61917
b919b7e
removed type comment and changed dtype to complex128
8b0fc27
Merge remote-tracking branch 'upstream/main' into issue_61917
2017397902 f9ee346
removed redundant comments
2017397902 2dda75a
mypy test failing
khemkaran10 3b7552b
mypy fixes
khemkaran10 6877e68
removed redundant check
khemkaran10 3302239
Merge remote-tracking branch 'upstream/main' into issue_61917
khemkaran10 880ee51
Merge branch 'main' into issue_61917
khemkaran10 b418bad
Merge branch 'main' into issue_61917
khemkaran10 bb1b626
Merge branch 'main' into issue_61917
khemkaran10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2081,16 +2081,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() | ||
|
Comment on lines
2082
to
+2086
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the comment about complex128 is no longer relevant? |
||
|
|
||
| elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion( | ||
| values.left.dtype | ||
|
|
@@ -2112,18 +2105,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") | ||
| ) | ||
|
Comment on lines
+2108
to
+2112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the comment from above be moved down here in some form? |
||
| 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 | ||
|
|
@@ -2134,18 +2130,13 @@ 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 = nc[:, None] | ||
| return self._from_combined(nc) | ||
| nc = unique(self._combined) | ||
khemkaran10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return self._from_combined(np.asarray(nc)[:, None]) | ||
|
|
||
|
|
||
| def _maybe_convert_platform_interval(values) -> ArrayLike: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.