-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Add typing annotation to assert_index_equal #26535
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
453875e
Add typing annotation to assert_index_equal
makbigc 8c70a15
Add annotation to the parameter check_categorical
makbigc f176ef5
merge
makbigc 411dd51
Add None to the typing annotation of assert_index_equal
makbigc fe9f8e8
Cast left and right Index as MultiIndex and set None optional
makbigc 571e64f
isort pandas/util/testing.py
makbigc 904a7f2
Move the casting statement up
makbigc 7de3444
None as the return type of assert_index_equal
makbigc cf96e22
Fix linting error
makbigc 8418a07
merging
makbigc de3fbf2
merging 2nd
makbigc 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 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import string | ||
import tempfile | ||
import traceback | ||
from typing import Union, cast | ||
import warnings | ||
import zipfile | ||
|
||
|
@@ -515,9 +516,14 @@ def equalContents(arr1, arr2): | |
return frozenset(arr1) == frozenset(arr2) | ||
|
||
|
||
def assert_index_equal(left, right, exact='equiv', check_names=True, | ||
check_less_precise=False, check_exact=True, | ||
check_categorical=True, obj='Index'): | ||
def assert_index_equal(left: Index, | ||
right: Index, | ||
exact: Union[bool, str] = 'equiv', | ||
check_names: bool = True, | ||
check_less_precise: Union[bool, int] = False, | ||
check_exact: bool = True, | ||
check_categorical: bool = True, | ||
obj: str = 'Index') -> None: | ||
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. Just a general comment but NoReturn may be applicable here at some point when we drop 3.5, though not sure if Optional[NoReturn] makes sense |
||
"""Check that left and right Index are equal. | ||
|
||
Parameters | ||
|
@@ -588,6 +594,9 @@ def _get_ilevel_values(index, level): | |
|
||
# MultiIndex special comparison for little-friendly error messages | ||
if left.nlevels > 1: | ||
left = cast(MultiIndex, left) | ||
right = cast(MultiIndex, right) | ||
|
||
for level in range(left.nlevels): | ||
# cannot use get_level_values here because it can change dtype | ||
llevel = _get_ilevel_values(left, level) | ||
|
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.
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.
Instead of a raw Index, is it possible to add a typing.TypeVar to _typing.py:
and then use that here (I'm not super aqianted with typing, so could be wrong)?
That would avoid the need to adapt the code below.
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.
this is ok as all of these are Index subclasses
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.
The point was that AnyIndex would capture .levels and other attributes that are not set on the base Index.
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.
I think this is OK too. MyPy would still complain about those attributes not existing on Index