Skip to content

Commit 632ea9d

Browse files
author
MarcoGorelli
committed
🚨 add warning if format cant be guessed
1 parent d1cdfd2 commit 632ea9d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/tools/datetimes.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str
132132
if (first_non_null := tslib.first_non_null(arr)) != -1:
133133
if type(first_non_nan_element := arr[first_non_null]) is str:
134134
# GH#32264 np.str_ object
135-
return guess_datetime_format(first_non_nan_element, dayfirst=dayfirst)
135+
guessed_format = guess_datetime_format(
136+
first_non_nan_element, dayfirst=dayfirst
137+
)
138+
if guessed_format is not None:
139+
return guessed_format
140+
warnings.warn(
141+
"Could not infer format - "
142+
"to ensure consistent parsing, specify a format.",
143+
stacklevel=find_stack_level(),
144+
)
136145
return None
137146

138147

0 commit comments

Comments
 (0)