Skip to content

Commit ed523ef

Browse files
committed
Remove warnings and fix functionality
1 parent 82ac17b commit ed523ef

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

pandas/_libs/tslibs/conversion.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ cdef _TSObject convert_str_to_tsobject(str ts, tzinfo tz,
610610
ts, &dts, &out_bestunit, &out_local,
611611
&out_tzoffset, False
612612
)
613-
if not string_to_dts_failed:
613+
if not string_to_dts_failed and not dayfirst:
614614
reso = get_supported_reso(out_bestunit)
615615
check_dts_bounds(&dts, reso)
616616
obj = _TSObject()

pandas/core/tools/datetimes.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str
135135
return guessed_format
136136
# If there are multiple non-null elements, warn about
137137
# how parsing might not be consistent
138-
if dayfirst or tslib.first_non_null(arr[first_non_null + 1 :]) != -1:
138+
if tslib.first_non_null(arr[first_non_null + 1 :]) != -1:
139139
warnings.warn(
140140
"Could not infer format, so each element will be parsed "
141-
"individually, falling back to `dateutil` which does not take the "
142-
"dayfirst parameter in consideration. To ensure parsing is "
141+
"individually, falling back to `dateutil`. To ensure parsing is "
143142
"consistent and as-expected, please specify a format.",
144143
UserWarning,
145144
stacklevel=find_stack_level(),

pandas/tests/tools/test_to_datetime.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -3007,11 +3007,9 @@ def test_parsers_dayfirst_yearfirst(
30073007
result2 = Timestamp(date_str)
30083008
assert result2 == expected
30093009

3010-
warn = UserWarning if dayfirst else None
3011-
with tm.assert_produces_warning(warn, match="Could not infer format"):
3012-
result3 = to_datetime(
3013-
date_str, dayfirst=dayfirst, yearfirst=yearfirst, cache=cache
3014-
)
3010+
result3 = to_datetime(
3011+
date_str, dayfirst=dayfirst, yearfirst=yearfirst, cache=cache
3012+
)
30153013

30163014
result4 = DatetimeIndex([date_str], dayfirst=dayfirst, yearfirst=yearfirst)[0]
30173015

0 commit comments

Comments
 (0)