-
-
Notifications
You must be signed in to change notification settings - Fork 143
Allow sorted() to work on Index #501
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
Either @twoertwein or @bashtage can review/approve/merge. Approvals from both not needed. Thanks! |
@@ -92,7 +96,11 @@ def test_column_contains() -> None: | |||
def test_column_sequence() -> None: | |||
df = pd.DataFrame([1, 2, 3]) | |||
col_list = list(df.columns) | |||
check(assert_type(col_list, List[Union[Scalar, Tuple[Hashable, ...]]]), list, int) | |||
check( | |||
assert_type(col_list, List[Union["IndexIterScalar", Tuple[Hashable, ...]]]), |
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.
Other tests (test_series.py) import from __future__ import annotations
to use tuple
/list
.
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 won't work at runtime on python 3.8. CI failed for me when I did that. You can do foo: list[int]
and that will be accepted, but if you are doing assert_type(col_list, list[Union["IndexIterScalar", tuple[Hashable, ...]]])
that will fail at runtime on 3.8 because the runtime for 3.8 can't parse something like list[int]
when it is not a typing annotation.
Thanks @Dr-Irv ! |
* trying SupportsRichComparisonT * create IndexIterScalar type for sorted(Index) to work * Use List not list, and Tuple not tuple for 3.8 compat
test_indexes.py:test_sorted_and_list()