From 6b50408f91aee05b622f5c1c9d7010c4f7b30fba Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Mon, 2 Jan 2023 13:01:25 +0000 Subject: [PATCH] improve warnings --- pandas/_libs/tslibs/parsing.pyx | 3 ++- pandas/core/tools/datetimes.py | 2 +- pandas/tests/io/parser/test_parse_dates.py | 2 +- pandas/tests/tslibs/test_parsing.py | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index aa95febfc9721..fac3d0446ed5b 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -1005,7 +1005,8 @@ cdef void _maybe_warn_about_dayfirst(format: str, bint dayfirst): ) if (day_index < month_index) and not dayfirst: warnings.warn( - f"Parsing dates in {format} format when dayfirst=False was specified. " + f"Parsing dates in {format} format when dayfirst=False (the default) " + "was specified. " "Pass `dayfirst=True` or specify a format to silence this warning.", UserWarning, stacklevel=find_stack_level(), diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index e7be2db293527..27328809e23d8 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -139,7 +139,7 @@ def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str return guessed_format warnings.warn( "Could not infer format, so each element will be parsed " - "individually by `dateutil`. To ensure parsing is " + "individually, falling back to `dateutil`. To ensure parsing is " "consistent and as-expected, please specify a format.", UserWarning, stacklevel=find_stack_level(), diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index ee9314c8779dd..6c05f5defe4fb 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -2052,7 +2052,7 @@ def test_parse_dot_separated_dates(all_parsers): name="a", ) warn = UserWarning - msg = "when dayfirst=False was specified" + msg = r"when dayfirst=False \(the default\) was specified" result = parser.read_csv_check_warnings( warn, msg, StringIO(data), parse_dates=True, index_col=0 ) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index 558c802fd70f6..a1a14674400c6 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -262,7 +262,8 @@ def test_guess_datetime_format_wrong_type_inputs(invalid_type_dt): def test_guess_datetime_format_no_padding(string, fmt, dayfirst, warning): # see gh-11142 msg = ( - f"Parsing dates in {fmt} format when dayfirst=False was specified. " + rf"Parsing dates in {fmt} format when dayfirst=False \(the default\) " + "was specified. " "Pass `dayfirst=True` or specify a format to silence this warning." ) with tm.assert_produces_warning(warning, match=msg):