Skip to content

Commit 9ffc3d3

Browse files
Remove imports + add if statement for NaTType
1 parent 195e405 commit 9ffc3d3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/core/tools/datetimes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
cast,
1313
overload,
1414
)
15-
import warnings
1615

1716
import numpy as np
1817

@@ -30,6 +29,7 @@
3029
timezones as libtimezones,
3130
)
3231
from pandas._libs.tslibs.conversion import cast_from_unit_vectorized
32+
from pandas._libs.missing import NAType
3333
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
3434
from pandas._libs.tslibs.parsing import (
3535
DateParseError,
@@ -42,7 +42,6 @@
4242
DateTimeErrorChoices,
4343
)
4444
from pandas.util._decorators import set_module
45-
from pandas.util._exceptions import find_stack_level
4645

4746
from pandas.core.dtypes.common import (
4847
ensure_object,
@@ -149,7 +148,11 @@ def _guess_datetime_format_for_array(
149148
# Look through the formats and see if one satisfies each item in the array
150149
for fmt in list(allowed_formats):
151150
try:
152-
[datetime.strptime(date_string, fmt) for date_string in arr if date_string]
151+
[
152+
datetime.strptime(date_string, fmt)
153+
for date_string in arr
154+
if date_string and not isinstance(date_string, NAType)
155+
]
153156
return fmt
154157
except ValueError:
155158
pass

0 commit comments

Comments
 (0)