-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: assert_index_equal ignoring names when check_order is false #47330
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
Changes from 1 commit
b4043d0
ff66a6e
8e75e34
fa08a58
d90de65
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 |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
"get_unanimous_names", | ||
"all_indexes_same", | ||
"default_index", | ||
"safe_sort_index", | ||
] | ||
|
||
|
||
|
@@ -157,23 +158,43 @@ def _get_combined_index( | |
index = ensure_index(index) | ||
|
||
if sort: | ||
try: | ||
array_sorted = safe_sort(index) | ||
array_sorted = cast(np.ndarray, array_sorted) | ||
if isinstance(index, MultiIndex): | ||
index = MultiIndex.from_tuples(array_sorted, names=index.names) | ||
else: | ||
index = Index(array_sorted, name=index.name) | ||
except TypeError: | ||
pass | ||
|
||
index = safe_sort_index(index) | ||
# GH 29879 | ||
if copy: | ||
index = index.copy() | ||
|
||
return index | ||
|
||
|
||
def safe_sort_index(index: Index) -> Index: | ||
""" | ||
Returns the sorted index | ||
|
||
We keep the dtypes and the name attributes. | ||
|
||
Parameters | ||
---------- | ||
index : an Index | ||
|
||
Returns | ||
------- | ||
Index | ||
""" | ||
try: | ||
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. following on from #47329 (comment) is our use of 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. None inside a mixed index still raises a TypeError 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. This gets adressed in #47331, we can probably remove the try there |
||
array_sorted = safe_sort(index) | ||
array_sorted = cast(np.ndarray, array_sorted) | ||
if isinstance(index, MultiIndex): | ||
index = MultiIndex.from_tuples( | ||
array_sorted, names=index.names, dtypes=index.dtypes | ||
) | ||
else: | ||
index = Index(array_sorted, name=index.name, dtype=index.dtype) | ||
except TypeError: | ||
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. maybe only have the safe_sort call in the try block? 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. A bit tricky, since array_sorted does not exist in the except block and we don't want to caste the Index again to an Index? 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. with an 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. Thanks very much. I am always forgetting that... Changed the code |
||
pass | ||
|
||
return index | ||
|
||
|
||
def union_indexes(indexes, sort: bool | None = True) -> Index: | ||
""" | ||
Return the union of indexes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DO NOT USE THIS SECTION
yep. this is ok here, in previous release notes the assert_* always go in the other section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked 1.3 notes to be sure there