diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index 9fb20aff8..cb0377ab8 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -42,6 +42,7 @@ from typing_extensions import ( from pandas._libs.interval import _OrderableT from pandas._typing import ( S1, + Axes, Dtype, DtypeArg, DtypeObj, @@ -81,7 +82,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: Literal["int"] | type_t[int | np.integer], copy: bool = ..., @@ -103,7 +104,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: Literal["float"] | type_t[float | np.floating], copy: bool = ..., @@ -129,7 +130,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: Literal["complex"] | type_t[complex | np.complexfloating], copy: bool = ..., @@ -152,7 +153,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: TimestampDtypeArg, copy: bool = ..., @@ -174,7 +175,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: PeriodDtype, copy: bool = ..., @@ -196,7 +197,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: TimedeltaDtypeArg, copy: bool = ..., @@ -218,7 +219,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype: Literal["Interval"], copy: bool = ..., @@ -241,7 +242,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable = ..., + data: Axes = ..., *, dtype: type[S1], copy: bool = ..., @@ -253,7 +254,7 @@ class Index(IndexOpsMixin[S1]): @overload def __new__( cls, - data: Iterable, + data: Axes, *, dtype=..., copy: bool = ..., diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 7ed87864c..3c1e85243 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -10,6 +10,7 @@ from datetime import ( from typing import overload from _typing import ( + Axes, Frequency, TimeZones, ) @@ -30,7 +31,6 @@ from pandas.core.series import ( from typing_extensions import Self from pandas._typing import ( - AnyArrayLike, DateAndDatetimeLike, Dtype, IntervalClosedType, @@ -44,7 +44,7 @@ from pandas.tseries.offsets import BaseOffset class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties): def __init__( self, - data: AnyArrayLike | list | tuple, + data: Axes, freq: Frequency = ..., tz: TimeZones = ..., ambiguous: str = ..., diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index 7b7067d65..1371f5dc8 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -27,7 +27,7 @@ from pandas._libs import ( ) from pandas._libs.tslibs import BaseOffset from pandas._typing import ( - AnyArrayLike, + Axes, TimedeltaConvertibleTypes, num, ) @@ -35,11 +35,7 @@ from pandas._typing import ( class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties): def __new__( cls, - data: ( - AnyArrayLike - | list[str] - | Sequence[dt.timedelta | Timedelta | np.timedelta64 | float] - ) = ..., + data: Sequence[dt.timedelta | Timedelta | np.timedelta64 | float] | Axes = ..., freq: str | BaseOffset = ..., closed: object = ..., dtype: Literal[" None: dt_ind = pd.date_range("2023-01-01", "2023-02-01") check(assert_type(dt_ind.delete(2), pd.DatetimeIndex), pd.DatetimeIndex) + + +def test_index_dict() -> None: + """Test passing an ordered iterables to Index and subclasses constructor GH828.""" + check( + assert_type(pd.Index({"Jan. 1, 2008": "New Year’s Day"}), "pd.Index[str]"), + pd.Index, + str, + ) + check( + assert_type( + pd.DatetimeIndex({"Jan. 1, 2008": "New Year’s Day"}), pd.DatetimeIndex + ), + pd.DatetimeIndex, + ) + check( + assert_type( + pd.TimedeltaIndex({pd.Timedelta(days=1): "New Year’s Day"}), + pd.TimedeltaIndex, + ), + pd.TimedeltaIndex, + )