Skip to content

Commit dbcb428

Browse files
Fix typing and add test + check for NaT
1 parent 9ffc3d3 commit dbcb428

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pandas/_libs/tslibs/parsing.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,6 @@ cdef str _fill_token(token: str, padding: int):
10711071
return token_filled
10721072

10731073

1074-
10751074
cpdef str get_rule_month(str source):
10761075
"""
10771076
Return starting month of given freq, default is December.

pandas/core/tools/datetimes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from __future__ import annotations
22

33
from collections import abc
4-
from datetime import date, datetime
4+
from datetime import (
5+
date,
6+
datetime,
7+
)
58
from functools import partial
69
from itertools import islice
710
from typing import (
@@ -29,8 +32,8 @@
2932
timezones as libtimezones,
3033
)
3134
from pandas._libs.tslibs.conversion import cast_from_unit_vectorized
32-
from pandas._libs.missing import NAType
3335
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
36+
from pandas._libs.tslibs.nattype import NaTType
3437
from pandas._libs.tslibs.parsing import (
3538
DateParseError,
3639
guess_datetime_format,
@@ -84,7 +87,6 @@
8487
Hashable,
8588
)
8689

87-
from pandas._libs.tslibs.nattype import NaTType
8890
from pandas._libs.tslibs.timedeltas import UnitChoices
8991

9092
from pandas import (
@@ -151,7 +153,7 @@ def _guess_datetime_format_for_array(
151153
[
152154
datetime.strptime(date_string, fmt)
153155
for date_string in arr
154-
if date_string and not isinstance(date_string, NAType)
156+
if date_string and not isinstance(date_string, NaTType)
155157
]
156158
return fmt
157159
except ValueError:

pandas/tests/tslibs/test_parsing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
from pandas._libs.tslibs import (
13+
NaT,
1314
parsing,
1415
strptime,
1516
)
@@ -19,7 +20,6 @@
1920
WASM,
2021
is_platform_windows,
2122
)
22-
from pandas.core.tools.datetimes import _guess_datetime_format_for_array
2323
import pandas.util._test_decorators as td
2424

2525
# Usually we wouldn't want this import in this test file (which is targeted at
@@ -30,6 +30,7 @@
3030
option_context,
3131
)
3232
import pandas._testing as tm
33+
from pandas.core.tools.datetimes import _guess_datetime_format_for_array
3334

3435

3536
@pytest.mark.skipif(WASM, reason="tzset is not available on WASM")
@@ -453,10 +454,10 @@ def test_parse_datetime_string_with_reso_yearfirst(yearfirst, input):
453454
np.array(["2025-08-09 14:30:00+0000", "2025-12-01 09:15:00-0500"]),
454455
),
455456
("%Y-%m-%d", np.array(["2025-08-09", None, "2025-12-01"])),
456-
(None, np.array(["2025/13/01", "not-a-date", ""])),
457+
(None, np.array(["2025/13/01", "not-a-date", "", NaT])),
457458
(
458459
None,
459-
np.array(["01/02/2025", "2025-02-01"]),
460+
np.array(["01/02/2025", "2025-02-01", np.nan]),
460461
),
461462
],
462463
)

0 commit comments

Comments
 (0)