diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 118d77ff71151..c5c5cc09a0e7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -92,7 +92,7 @@ repos: args: [--disable=all, --enable=redefined-outer-name] stages: [manual] - repo: https://github.com/PyCQA/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/asottile/pyupgrade diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 410b4fc0bf9c0..178ec1076bfda 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -891,6 +891,7 @@ def read_csv( "A strict version of it is now the default, see " "https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. " "You can safely remove this argument.", + FutureWarning, stacklevel=find_stack_level(), ) # locals() should never be modified @@ -1207,6 +1208,17 @@ def read_table( storage_options: StorageOptions = None, use_nullable_dtypes: bool | lib.NoDefault = lib.no_default, ) -> DataFrame | TextFileReader: + if infer_datetime_format is not lib.no_default: + warnings.warn( + "The argument 'infer_datetime_format' is deprecated and will " + "be removed in a future version. " + "A strict version of it is now the default, see " + "https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. " + "You can safely remove this argument.", + FutureWarning, + stacklevel=find_stack_level(), + ) + # locals() should never be modified kwds = locals().copy() del kwds["filepath_or_buffer"] diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index fc477a899d089..9aebadd833506 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -1290,16 +1290,21 @@ def test_parse_dates_empty_string(all_parsers): tm.assert_frame_equal(result, expected) -def test_parse_dates_infer_datetime_format_warning(all_parsers): - # GH 49024 +@pytest.mark.parametrize( + "reader", ["read_csv_check_warnings", "read_table_check_warnings"] +) +def test_parse_dates_infer_datetime_format_warning(all_parsers, reader): + # GH 49024, 51017 parser = all_parsers data = "Date,test\n2012-01-01,1\n,2" - parser.read_csv_check_warnings( - UserWarning, + + getattr(parser, reader)( + FutureWarning, "The argument 'infer_datetime_format' is deprecated", StringIO(data), parse_dates=["Date"], infer_datetime_format=True, + sep=",", )