Skip to content

Commit c6398b3

Browse files
GH1352 Add passing a dict with integer for pd.to_datetime
1 parent 3033eea commit c6398b3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas-stubs/core/tools/datetimes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DatetimeScalar: TypeAlias = Scalar | datetime | np.datetime64 | date
3838

3939
DatetimeScalarOrArrayConvertible: TypeAlias = DatetimeScalar | ArrayConvertible
4040

41-
DatetimeDictArg: TypeAlias = list[Scalar] | tuple[Scalar, ...] | AnyArrayLike
41+
DatetimeDictArg: TypeAlias = list[Scalar] | tuple[Scalar, ...] | AnyArrayLike | int
4242

4343
class YearMonthDayDict(TypedDict, total=True):
4444
year: DatetimeDictArg

tests/test_timefuncs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,23 @@ def test_to_datetime_series() -> None:
13341334
check(assert_type(pd.to_datetime(d), "TimestampSeries"), pd.Series)
13351335
check(assert_type(pd.to_datetime(d_ex), "TimestampSeries"), pd.Series)
13361336

1337+
# GH1352
1338+
ts = pd.date_range("2023-10-01", "2024-05-01", freq="1h")
1339+
check(
1340+
assert_type(
1341+
pd.to_datetime(
1342+
{
1343+
"year": ts.year,
1344+
"month": ts.month,
1345+
"day": 1,
1346+
}
1347+
),
1348+
"TimestampSeries",
1349+
),
1350+
pd.Series,
1351+
pd.Timestamp,
1352+
)
1353+
13371354

13381355
def test_to_datetime_array() -> None:
13391356
check(assert_type(pd.to_datetime([1, 2, 3]), pd.DatetimeIndex), pd.DatetimeIndex)

0 commit comments

Comments
 (0)