-
-
Notifications
You must be signed in to change notification settings - Fork 143
add operators for Index #504
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
Conversation
For this PR, would like BOTH @bashtage and @twoertwein to approve, and whomever does the second approval, can do the merge. Thanks. |
I think |
Based on discussion here: python/mypy#14424 I changed the way we detect invalid |
check(assert_type(i1 % i2, pd.Index), pd.Index) | ||
check(assert_type(i1 % 10, pd.Index), pd.Index) | ||
check(assert_type(10 % i1, pd.Index), pd.Index) | ||
check(assert_type(divmod(i1, i2), Tuple[pd.Index, pd.Index]), tuple) |
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.
Not needed but could also check the tuple elements: check(..., tuple, pd.Index)
@bashtage awaiting your approval/merge |
@bashtage can you review? |
@twoertwein haven't heard from @bashtage in a few weeks so can you merge it? Thanks. |
i1 | i2, # type:ignore[operator] # pyright: ignore[reportGeneralTypeIssues] | ||
Never, | ||
) | ||
assert_type( # type: ignore[assert-type] |
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.
Some of the checks have an ignore for assert_type
and some don't. Why do some need an ignore?
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.
It has to do with how mypy
processes Never
with certain operators and arguments. If you look carefully, you'll see that the # ignore[assert-type]
is occurring on any operator that has a numerical operand. Without the ignore
, mypy
says the assert_type()
is wrong, thinking the result is Any
. Probably some kind of mypy
error, although the interpretation of the Never
result is ambiguous.
Thanks @Dr-Irv |
* add operators for Index * Fix OpsMixin using TypeVar * detect Never as argument
Index
operators missing #405(test_indexes.py:test_index_operators()
Some notes:
OpsMixin
, but we'd need to use return types ofSelf
andmypy
doesn't support that yet. I put a comment inarraylike.pyi
about that.Index
, where we don't know the dtype of theIndex
. Could eventually improve this if we ever makeIndex
a Generic type.My philosophy is that this is "good enough for now", and if we get reports of issues on specific Index subclasses, we can then fix them going forward, rather than doing a complete set of tests now for all the Index subclasses.