-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add typing annotation to assert_index_equal #26535
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 5 commits
453875e
8c70a15
f176ef5
411dd51
fe9f8e8
571e64f
904a7f2
7de3444
cf96e22
8418a07
de3fbf2
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import string | ||
import tempfile | ||
import traceback | ||
from typing import cast, Union, Optional | ||
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') -> Optional[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. Can just do |
||
"""Check that left and right Index are equal. | ||
|
||
Parameters | ||
|
@@ -599,6 +605,8 @@ def _get_ilevel_values(index, level): | |
check_less_precise=check_less_precise, | ||
check_exact=check_exact, obj=lobj) | ||
# get_level_values may change dtype | ||
left = cast(MultiIndex, left) | ||
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. Can you move these to line 597? That is specifically where the inference of a new type should occur would logically fit better there |
||
right = cast(MultiIndex, right) | ||
_check_types(left.levels[level], right.levels[level], obj=obj) | ||
|
||
# skip exact index checking when `check_categorical` is False | ||
|
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