pandas-dev / pandas-stubs

Public type stubs for pandas
BSD 3-Clause "New" or "Revised" License
229 stars 123 forks source link

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

Open randolf-scholz opened 9 months ago

randolf-scholz commented 9 months ago
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 commented 9 months ago

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 commented 9 months ago

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

twoertwein commented 9 months ago

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 https://github.com/python/typing/issues/256#issuecomment-1732414512 (but that is for a Sequence, not an Iterable - but Sequence might be more array-like than any iterable).