Skip to content

Argument 1 to "DatetimeIndex" has incompatible type "dict[str, str]" #828

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

Closed
randolf-scholz opened this issue Dec 15, 2023 · 7 comments · Fixed by #1202
Closed

Argument 1 to "DatetimeIndex" has incompatible type "dict[str, str]" #828

randolf-scholz opened this issue Dec 15, 2023 · 7 comments · Fixed by #1202
Labels
Index Related to the Index class or subclasses

Comments

@randolf-scholz
Copy link
Contributor

import pandas as pd

anomalies = pd.DatetimeIndex({
    "Jan. 1, 2008": "New Year’s Day",
    "Jan. 21, 2008": "Martin Luther King Jr. Day",
    "Feb. 18, 2008": "Washington’s Birthday",
    "Mar. 9, 2008": "Anomaly day",
    "May 26, 2008": "Memorial Day",
    "Jul. 4, 2008": "Independence Day",
    "Sep. 1, 2008": "Labor Day",
    "Oct. 13, 2008": "Columbus Day",
    "Nov. 11, 2008": "Veterans Day",
    "Nov. 27, 2008": "Thanksgiving",
    "Dec. 25, 2008": "Christmas Day",
    "Jan. 1, 2009": "New Year’s Day",
    "Jan. 19, 2009": "Martin Luther King Jr. Day",
    "Feb. 16, 2009": "Washington’s Birthday",
    "Mar. 8, 2009": "Anomaly day",
})
@twoertwein
Copy link
Member

dict[str, str] is not officially documented but Iterable[str] (excluding str itself) might be "array-like" and would allow dict[str, Any].

@randolf-scholz
Copy link
Contributor Author

Btw. I have a potential workaround for the Iterable[str] vs str, but it's not sure if it will be accepted: python/cpython#112319

@twoertwein
Copy link
Member

Btw. I have a potential workaround for the Iterable[str] vs str, but it's not sure if it will be accepted: python/cpython#112319

In pandas we use python/typing#256 (comment) (but that is for a Sequence, not an Iterable - but Sequence might be more array-like than any iterable).

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 10, 2025

While this does work, it isn't documented. Related issue in pandas here: pandas-dev/pandas#55425

@Dr-Irv Dr-Irv added the pandas_docs For issues where there is a conflict in behavior with pandas docs and stubs that needs resolution label Jan 10, 2025
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 12, 2025

In pandas dev meeting on 2/12/25, we agreed to accept "ordered iterables", so that would include what is now defined as Axes in the stubs.

Need to modify the arguments in various Index.__new__() and subclasses of Index in either __new__() and/or __init__() to accept Axes rather than Iterable (or whatever else is there)

@Dr-Irv Dr-Irv added Index Related to the Index class or subclasses and removed pandas_docs For issues where there is a conflict in behavior with pandas docs and stubs that needs resolution labels Feb 12, 2025
@loicdiridollou
Copy link
Member

For this issue does this mean that the dicts are supported or not? I know that now python will always return the same order for dicts but Axes does not contain dict.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 26, 2025

For this issue does this mean that the dicts are supported or not? I know that now python will always return the same order for dicts but Axes does not contain dict.

Yes, Axes does have dict in it. So the change suggested at #828 (comment) should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants