Skip to content

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

Merged
merged 4 commits into from
Jan 8, 2023
Merged

Conversation

Dr-Irv
Copy link
Collaborator

@Dr-Irv Dr-Irv commented Jan 7, 2023

@Dr-Irv Dr-Irv requested review from twoertwein and bashtage January 7, 2023 21:44
@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 7, 2023

Either @twoertwein or @bashtage can review/approve/merge. Approvals from both not needed. Thanks!

@Dr-Irv Dr-Irv changed the title Issue497 Allow sorted() to work on Index Jan 7, 2023
@@ -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, ...]]]),
Copy link
Member

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.

Copy link
Collaborator Author

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.

@twoertwein twoertwein merged commit c9a8a73 into pandas-dev:main Jan 8, 2023
@twoertwein
Copy link
Member

Thanks @Dr-Irv !

@Dr-Irv Dr-Irv deleted the issue497 branch February 4, 2023 17:04
twoertwein pushed a commit to twoertwein/pandas-stubs that referenced this pull request Apr 1, 2023
* trying SupportsRichComparisonT

* create IndexIterScalar type for sorted(Index) to work

* Use List not list, and Tuple not tuple for 3.8 compat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mypy complaining on sorted, min and max builtins on Version 1.5.2.221213
2 participants