From e90bb56c33edf4f96c872cecb5f3c591576ce2d9 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Sat, 1 Jun 2024 05:10:37 +0300 Subject: [PATCH] ENH: Warn when to_datetime falls back to dateutil when dayfirst is passed --- pandas/core/tools/datetimes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index b01cdb335ec46..eaca0479ab931 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -135,10 +135,11 @@ def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str return guessed_format # If there are multiple non-null elements, warn about # how parsing might not be consistent - if tslib.first_non_null(arr[first_non_null + 1 :]) != -1: + if dayfirst or tslib.first_non_null(arr[first_non_null + 1 :]) != -1: warnings.warn( "Could not infer format, so each element will be parsed " - "individually, falling back to `dateutil`. To ensure parsing is " + "individually, falling back to `dateutil` which does not take the " + "dayfirst parameter in consideration. To ensure parsing is " "consistent and as-expected, please specify a format.", UserWarning, stacklevel=find_stack_level(),