Skip to content

Commit 611f1fc

Browse files
GH828 Add dict
1 parent 26dd14b commit 611f1fc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from datetime import (
1010
from typing import overload
1111

1212
from _typing import (
13+
Axes,
1314
Frequency,
1415
TimeZones,
1516
)
@@ -44,7 +45,7 @@ from pandas.tseries.offsets import BaseOffset
4445
class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
4546
def __init__(
4647
self,
47-
data: AnyArrayLike | list | tuple,
48+
data: Axes | AnyArrayLike,
4849
freq: Frequency = ...,
4950
tz: TimeZones = ...,
5051
ambiguous: str = ...,

pandas-stubs/core/indexes/timedeltas.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ from pandas._libs import (
2828
from pandas._libs.tslibs import BaseOffset
2929
from pandas._typing import (
3030
AnyArrayLike,
31+
Axes,
3132
TimedeltaConvertibleTypes,
3233
num,
3334
)
@@ -37,8 +38,8 @@ class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties
3738
cls,
3839
data: (
3940
AnyArrayLike
40-
| list[str]
4141
| Sequence[dt.timedelta | Timedelta | np.timedelta64 | float]
42+
| Axes
4243
) = ...,
4344
freq: str | BaseOffset = ...,
4445
closed: object = ...,

tests/test_indexes.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,22 @@ def test_index_delete() -> None:
13241324

13251325

13261326
def test_index_dict() -> None:
1327-
if TYPE_CHECKING_INVALID_USAGE:
1328-
pd.DatetimeIndex(
1329-
{ # type: ignore[arg-type]
1330-
"Jan. 1, 2008": "New Year’s Day" # pyright: ignore[reportArgumentType]
1331-
}
1332-
)
1327+
"""Test passing an ordered iterables to Index and subclasses constructor GH828."""
1328+
check(
1329+
assert_type(pd.Index({"Jan. 1, 2008": "New Year’s Day"}), "pd.Index[str]"),
1330+
pd.Index,
1331+
str,
1332+
)
1333+
check(
1334+
assert_type(
1335+
pd.DatetimeIndex({"Jan. 1, 2008": "New Year’s Day"}), pd.DatetimeIndex
1336+
),
1337+
pd.DatetimeIndex,
1338+
)
1339+
check(
1340+
assert_type(
1341+
pd.TimedeltaIndex({pd.Timedelta(days=1): "New Year’s Day"}),
1342+
pd.TimedeltaIndex,
1343+
),
1344+
pd.TimedeltaIndex,
1345+
)

0 commit comments

Comments
 (0)