From c23ad4603af60829f87a525dd65e14379bee45ef Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 7 May 2024 10:55:34 -0700 Subject: [PATCH] CLN: Remove deprecated read_csv(infer_datetime_format=) --- doc/source/user_guide/io.rst | 7 ----- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/io/parsers/readers.py | 34 ---------------------- pandas/tests/io/parser/test_parse_dates.py | 19 ------------ 4 files changed, 1 insertion(+), 60 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index b5cc8c43ae143..bd14abdd9408c 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -276,12 +276,6 @@ parse_dates : boolean or list of ints or names or list of lists or dict, default .. note:: A fast-path exists for iso8601-formatted dates. -infer_datetime_format : boolean, default ``False`` - If ``True`` and parse_dates is enabled for a column, attempt to infer the - datetime format to speed up the processing. - - .. deprecated:: 2.0.0 - A strict version of this argument is now the default, passing it has no effect. keep_date_col : boolean, default ``False`` If ``True`` and parse_dates specifies combining multiple columns then keep the original columns. @@ -1639,7 +1633,6 @@ Options that are unsupported by the pyarrow engine which are not covered by the * ``decimal`` * ``iterator`` * ``dayfirst`` -* ``infer_datetime_format`` * ``verbose`` * ``skipinitialspace`` * ``low_memory`` diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 278971ef88a0f..a37da9d5f1208 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -254,6 +254,7 @@ Removal of prior version deprecations/changes - Enforced deprecation of :meth:`offsets.Tick.delta`, use ``pd.Timedelta(obj)`` instead (:issue:`55498`) - Enforced deprecation of ``axis=None`` acting the same as ``axis=0`` in the DataFrame reductions ``sum``, ``prod``, ``std``, ``var``, and ``sem``, passing ``axis=None`` will now reduce over both axes; this is particularly the case when doing e.g. ``numpy.sum(df)`` (:issue:`21597`) - Enforced deprecation of ``core.internals`` members ``Block``, ``ExtensionBlock``, and ``DatetimeTZBlock`` (:issue:`58467`) +- Enforced deprecation of argument ``infer_datetime_format`` in :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`) - Enforced deprecation of non-standard (``np.ndarray``, :class:`ExtensionArray`, :class:`Index`, or :class:`Series`) argument to :func:`api.extensions.take` (:issue:`52981`) - Enforced deprecation of parsing system timezone strings to ``tzlocal``, which depended on system timezone, pass the 'tz' keyword instead (:issue:`50791`) - Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`) diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 70f9a68244164..b9235f7068630 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -118,7 +118,6 @@ class _read_shared(TypedDict, Generic[HashableT], total=False): na_filter: bool skip_blank_lines: bool parse_dates: bool | Sequence[Hashable] | None - infer_datetime_format: bool | lib.NoDefault keep_date_col: bool | lib.NoDefault date_parser: Callable | lib.NoDefault date_format: str | dict[Hashable, str] | None @@ -323,15 +322,6 @@ class _read_shared(TypedDict, Generic[HashableT], total=False): :func:`~pandas.read_csv`. Note: A fast-path exists for iso8601-formatted dates. -infer_datetime_format : bool, default False - If ``True`` and ``parse_dates`` is enabled, pandas will attempt to infer the - format of the ``datetime`` strings in the columns, and if it can be inferred, - switch to a faster method of parsing them. In some cases this can increase - the parsing speed by 5-10x. - - .. deprecated:: 2.0.0 - A strict version of this argument is now the default, passing it has no effect. - keep_date_col : bool, default False If ``True`` and ``parse_dates`` specifies combining multiple columns then keep the original columns. @@ -758,7 +748,6 @@ def read_csv( skip_blank_lines: bool = True, # Datetime Handling parse_dates: bool | Sequence[Hashable] | None = None, - infer_datetime_format: bool | lib.NoDefault = lib.no_default, keep_date_col: bool | lib.NoDefault = lib.no_default, date_parser: Callable | lib.NoDefault = lib.no_default, date_format: str | dict[Hashable, str] | None = None, @@ -822,17 +811,6 @@ def read_csv( stacklevel=find_stack_level(), ) - 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(), - ) - if delim_whitespace is not lib.no_default: # GH#55569 warnings.warn( @@ -949,7 +927,6 @@ def read_table( skip_blank_lines: bool = True, # Datetime Handling parse_dates: bool | Sequence[Hashable] | None = None, - infer_datetime_format: bool | lib.NoDefault = lib.no_default, keep_date_col: bool | lib.NoDefault = lib.no_default, date_parser: Callable | lib.NoDefault = lib.no_default, date_format: str | dict[Hashable, str] | None = None, @@ -1004,17 +981,6 @@ def read_table( stacklevel=find_stack_level(), ) - 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(), - ) - if delim_whitespace is not lib.no_default: # GH#55569 warnings.warn( diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 8968948df5fa9..62e4f6d8c40b5 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -1383,25 +1383,6 @@ def test_parse_dates_empty_string(all_parsers): tm.assert_frame_equal(result, expected) -@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" - - getattr(parser, reader)( - FutureWarning, - "The argument 'infer_datetime_format' is deprecated", - StringIO(data), - parse_dates=["Date"], - infer_datetime_format=True, - sep=",", - raise_on_extra_warnings=False, - ) - - @pytest.mark.parametrize( "reader", ["read_csv_check_warnings", "read_table_check_warnings"] )