From 8bdf208e765dbe606e57f3202b42c18f6d475c42 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:35:19 -0800 Subject: [PATCH 1/2] Deprecate parameters similar to pandas 2.2 --- python/cudf/cudf/core/index.py | 5 +++++ python/cudf/cudf/core/indexed_frame.py | 6 ++++++ python/cudf/cudf/core/tools/datetimes.py | 8 ++++++++ python/cudf/cudf/core/tools/numeric.py | 7 +++++++ python/cudf/cudf/tests/test_datetime.py | 5 +++++ python/cudf/cudf/tests/test_numerical.py | 5 +++++ 6 files changed, 36 insertions(+) diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index c05d89e7279..ea8ba154922 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -2402,6 +2402,11 @@ def __init__( raise NotImplementedError("freq is not yet supported") if unit is not None: + warnings.warn( + "The 'unit' keyword is " + "deprecated and will be removed in a future version. ", + FutureWarning, + ) raise NotImplementedError( "unit is not yet supported, alternatively " "dtype parameter is supported" diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index 659e323c57d..3f591fb545f 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -3918,6 +3918,12 @@ def resample( """ import cudf.core.resample + if kind is not None: + warnings.warn( + "The 'kind' keyword in is " + "deprecated and will be removed in a future version. ", + FutureWarning, + ) if (axis, convention, kind, loffset, base, origin, offset) != ( 0, "start", diff --git a/python/cudf/cudf/core/tools/datetimes.py b/python/cudf/cudf/core/tools/datetimes.py index 928154e10fd..529296da6a2 100644 --- a/python/cudf/cudf/core/tools/datetimes.py +++ b/python/cudf/cudf/core/tools/datetimes.py @@ -162,6 +162,14 @@ def to_datetime( f"{errors=} is not implemented when arg is not scalar-like" ) + if errors == "ignore": + warnings.warn( + "errors='ignore' is deprecated and will raise in a future version. " + "Use to_datetime without passing `errors` and catch exceptions " + "explicitly instead", + FutureWarning, + ) + if infer_datetime_format in {None, False}: warnings.warn( "`infer_datetime_format` is deprecated and will " diff --git a/python/cudf/cudf/core/tools/numeric.py b/python/cudf/cudf/core/tools/numeric.py index 8991fbe1c13..e1424459c8f 100644 --- a/python/cudf/cudf/core/tools/numeric.py +++ b/python/cudf/cudf/core/tools/numeric.py @@ -95,6 +95,13 @@ def to_numeric(arg, errors="raise", downcast=None): if errors not in {"raise", "ignore", "coerce"}: raise ValueError("invalid error value specified") + elif errors == "ignore": + warnings.warn( + "errors='ignore' is deprecated and will raise in a future version. " + "Use to_numeric without passing `errors` and catch exceptions " + "explicitly instead", + FutureWarning, + ) if downcast not in {None, "integer", "signed", "unsigned", "float"}: raise ValueError("invalid downcasting method provided") diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index 1f24337d28b..5596be30cfa 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -2468,3 +2468,8 @@ def test_datetime_raise_warning(freqstr): ) with pytest.warns(FutureWarning): t.dt.ceil(freqstr) + + +def test_to_datetime_errors_ignore_deprecated(): + with pytest.warns(FutureWarning): + cudf.to_datetime("2001-01-01 00:04:45", errors="ignore") diff --git a/python/cudf/cudf/tests/test_numerical.py b/python/cudf/cudf/tests/test_numerical.py index 2139e7b9860..f8d30bad792 100644 --- a/python/cudf/cudf/tests/test_numerical.py +++ b/python/cudf/cudf/tests/test_numerical.py @@ -422,3 +422,8 @@ def test_series_to_numeric_preserve_index_name(klass): result = cudf.to_numeric(ser) expected = cudf.Series([1] * 8, index=range(2, 10), name="name") assert_eq(result, expected) + + +def test_to_datetime_errors_ignore_deprecated(): + with pytest.warns(FutureWarning): + cudf.to_datetime("1", errors="ignore") From b32e7c0e592a6f9492b522c526052352dd7ab77e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:50:54 -0800 Subject: [PATCH 2/2] Fix test_to_numeric_error --- python/cudf/cudf/tests/test_numerical.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/python/cudf/cudf/tests/test_numerical.py b/python/cudf/cudf/tests/test_numerical.py index f8d30bad792..fb1bc580aa4 100644 --- a/python/cudf/cudf/tests/test_numerical.py +++ b/python/cudf/cudf/tests/test_numerical.py @@ -5,7 +5,8 @@ import pytest import cudf -from cudf.testing._utils import NUMERIC_TYPES, assert_eq +from cudf.core._compat import PANDAS_GE_220 +from cudf.testing._utils import NUMERIC_TYPES, assert_eq, expect_warning_if from cudf.utils.dtypes import np_dtypes_to_pandas_dtypes @@ -372,8 +373,10 @@ def test_to_numeric_error(data, errors): ): cudf.to_numeric(data, errors=errors) else: - expect = pd.to_numeric(data, errors=errors) - got = cudf.to_numeric(data, errors=errors) + with expect_warning_if(PANDAS_GE_220 and errors == "ignore"): + expect = pd.to_numeric(data, errors=errors) + with expect_warning_if(errors == "ignore"): + got = cudf.to_numeric(data, errors=errors) assert_eq(expect, got) @@ -422,8 +425,3 @@ def test_series_to_numeric_preserve_index_name(klass): result = cudf.to_numeric(ser) expected = cudf.Series([1] * 8, index=range(2, 10), name="name") assert_eq(result, expected) - - -def test_to_datetime_errors_ignore_deprecated(): - with pytest.warns(FutureWarning): - cudf.to_datetime("1", errors="ignore")