Skip to content

Commit

Permalink
Enforce deprecations and add clarifications around existing deprecati…
Browse files Browse the repository at this point in the history
…ons (#13710)

Fixes: #13619
This PR enforces deprecation warnings and adds comments around the existing deprecation warnings that shouldn't be dropped right now.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #13710
  • Loading branch information
galipremsagar authored Jul 17, 2023
1 parent de20aa7 commit 494535e
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 76 deletions.
2 changes: 2 additions & 0 deletions docs/cudf/source/developer_guide/contributing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ For more information on how to use pre-commit hooks, see the code formatting sec
cuDF follows the policy of deprecating code for one release prior to removal.
For example, if we decide to remove an API during the 22.08 release cycle,
it will be marked as deprecated in the 22.08 release and removed in the 22.10 release.
Note that if it is explicitly mentioned in a comment (like `# Do not remove until..`),
do not enforce the deprecation by removing the affected code until the condition in the comment is met.
All internal usage of deprecated APIs in cuDF should be removed when the API is deprecated.
This prevents users from encountering unexpected deprecation warnings when using other (non-deprecated) APIs.
The documentation for the API should also be updated to reflect its deprecation.
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def is_monotonic(self):
-------
bool
"""
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"is_monotonic is deprecated and will be removed in a future "
"version. Use is_monotonic_increasing instead.",
Expand Down Expand Up @@ -880,6 +881,7 @@ def is_numeric(self):
>>> idx.is_numeric()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_numeric is deprecated. "
"Use cudf.api.types.is_any_real_numeric_dtype instead",
Expand Down Expand Up @@ -924,6 +926,7 @@ def is_boolean(self):
>>> idx.is_boolean()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_boolean is deprecated. "
"Use cudf.api.types.is_bool_dtype instead",
Expand Down Expand Up @@ -968,6 +971,7 @@ def is_integer(self):
>>> idx.is_integer()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_integer is deprecated. "
"Use cudf.api.types.is_integer_dtype instead",
Expand Down Expand Up @@ -1019,6 +1023,7 @@ def is_floating(self):
>>> idx.is_floating()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_floating is deprecated. "
"Use cudf.api.types.is_float_dtype instead",
Expand Down Expand Up @@ -1064,6 +1069,7 @@ def is_object(self):
>>> idx.is_object()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_object is deprecated. "
"Use cudf.api.types.is_object_dtype instead",
Expand Down Expand Up @@ -1116,6 +1122,7 @@ def is_categorical(self):
>>> s.index.is_categorical()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_categorical is deprecated. "
"Use cudf.api.types.is_categorical_dtype instead",
Expand Down Expand Up @@ -1162,6 +1169,7 @@ def is_interval(self):
>>> idx.is_interval()
False
"""
# Do not remove until pandas removes this.
warnings.warn(
f"{type(self).__name__}.is_interval is deprecated. "
"Use cudf.api.types.is_interval_dtype instead",
Expand Down Expand Up @@ -1541,6 +1549,7 @@ def get_slice_bound(self, label, side: str, kind=None) -> int:
Index of label.
"""
if kind is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"'kind' argument in get_slice_bound is deprecated and will be "
"removed in a future version.",
Expand Down
1 change: 1 addition & 0 deletions python/cudf/cudf/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def factorize(
"Specify `use_na_sentinel=True` to use the sentinel value -1, "
"and `use_na_sentinel=False` to encode NA values.",
)
# Do not remove until pandas 2.0 support is added.
warnings.warn(msg, FutureWarning)

if size_hint:
Expand Down
15 changes: 7 additions & 8 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def as_ordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:
Categories (3, int64): [1 < 2 < 10]
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The inplace parameter is deprecated and will be removed in a "
"future release. set_ordered will always return a new Series "
Expand Down Expand Up @@ -272,6 +273,7 @@ def as_unordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:
Categories (3, int64): [1, 2, 10]
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The inplace parameter is deprecated and will be removed in a "
"future release. set_ordered will always return a new Series "
Expand Down Expand Up @@ -341,6 +343,7 @@ def add_categories(
Categories (5, int64): [1, 2, 0, 3, 4]
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The `inplace` parameter in cudf.Series.cat.add_categories "
"is deprecated and will be removed in a future version of "
Expand Down Expand Up @@ -460,6 +463,7 @@ def remove_categories(
Categories (2, int64): [1, 2]
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The `inplace` parameter in "
"cudf.Series.cat.remove_categories is deprecated and "
Expand Down Expand Up @@ -578,6 +582,7 @@ def set_categories(
Categories (2, int64): [1, 10]
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The `inplace` parameter in cudf.Series.cat.set_categories is "
"deprecated and will be removed in a future version of cudf. "
Expand Down Expand Up @@ -666,6 +671,7 @@ def reorder_categories(
old categories
"""
if inplace:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"The `inplace` parameter in "
"cudf.Series.cat.reorder_categories is deprecated "
Expand Down Expand Up @@ -1042,14 +1048,7 @@ def data_array_view(
) -> cuda.devicearray.DeviceNDArray:
return self.codes.data_array_view(mode=mode)

def unique(self, preserve_order=True) -> CategoricalColumn:
if preserve_order is not True:
warnings.warn(
"The preserve_order argument is deprecated. It will be "
"removed in a future version. As of now, unique always "
"preserves order regardless of the argument's value.",
FutureWarning,
)
def unique(self) -> CategoricalColumn:
codes = self.as_numerical.unique()
return column.build_categorical_column(
categories=self.categories,
Expand Down
9 changes: 1 addition & 8 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,17 +1149,10 @@ def searchsorted(
values, side, ascending=ascending, na_position=na_position
)

def unique(self, preserve_order=True) -> ColumnBase:
def unique(self) -> ColumnBase:
"""
Get unique values in the data
"""
if preserve_order is not True:
warnings.warn(
"The preserve_order argument is deprecated. It will be "
"removed in a future version. As of now, unique always "
"preserves order regardless of the argument's value.",
FutureWarning,
)
return drop_duplicates([self], keep="first")[0]

def serialize(self) -> Tuple[dict, list]:
Expand Down
21 changes: 21 additions & 0 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ def as_string_column(
"cudf.core.column.StringColumn", as_column([], dtype="object")
)

def __pow__(self, other):
if isinstance(other, int):
if other == 0:
res = cudf.core.column.full(
size=len(self), fill_value=1, dtype=self.dtype
)
if self.nullable:
res = res.set_mask(self.mask)
return res
elif other < 0:
raise TypeError("Power of negative integers not supported.")
res = self
for _ in range(other - 1):
res = self * res
return res
else:
raise NotImplementedError(
f"__pow__ of types {self.dtype} and {type(other)} is "
"not yet implemented."
)

# Decimals in libcudf don't support truediv, see
# https://github.com/rapidsai/cudf/pull/7435 for explanation.
def __truediv__(self, other):
Expand Down
16 changes: 2 additions & 14 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4848,6 +4848,7 @@ def describe(
if datetime_is_numeric:
default_include.append("datetime")
else:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"`datetime_is_numeric` is deprecated. Specify "
"`datetime_is_numeric=True` to silence this "
Expand Down Expand Up @@ -5795,6 +5796,7 @@ def _reduce(
)

if numeric_only is None and op in numeric_ops:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"The default value of numeric_only in DataFrame.{op} "
"is deprecated. In a future version, it will default "
Expand Down Expand Up @@ -6268,26 +6270,12 @@ def to_csv(
encoding=None,
compression=None,
lineterminator=None,
line_terminator=None,
chunksize=None,
storage_options=None,
):
"""{docstring}"""
from cudf.io import csv

if line_terminator is not None:
warnings.warn(
"line_terminator is a deprecated keyword argument, "
"use lineterminator instead.",
FutureWarning,
)
if lineterminator is not None:
warnings.warn(
f"Ignoring {line_terminator=} in favor "
f"of {lineterminator=}"
)
else:
lineterminator = line_terminator
if lineterminator is None:
lineterminator = os.linesep
return csv.to_csv(
Expand Down
29 changes: 0 additions & 29 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,35 +2483,6 @@ def any(self, axis=0, skipna=True, level=None, **kwargs):
**kwargs,
)

@_cudf_nvtx_annotate
def sum_of_squares(self, dtype=None):
"""Return the sum of squares of values.
Parameters
----------
dtype: data type
Data type to cast the result to.
Returns
-------
Series
Examples
--------
>>> import cudf
>>> df = cudf.DataFrame({'a': [3, 2, 3, 4], 'b': [7, 0, 10, 10]})
>>> df.sum_of_squares()
a 38
b 249
dtype: int64
"""
warnings.warn(
f"Support for {self.__class__}.sum_of_squares is deprecated and "
"will be removed",
FutureWarning,
)
return self._reduce("sum_of_squares", dtype=dtype)

@_cudf_nvtx_annotate
def median(
self, axis=None, skipna=True, level=None, numeric_only=None, **kwargs
Expand Down
4 changes: 4 additions & 0 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def __init__(

def __iter__(self):
if isinstance(self._by, list) and len(self._by) == 1:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"In a future version of cudf, a length 1 tuple will be "
"returned when iterating over a groupby with a grouper equal "
Expand Down Expand Up @@ -2062,6 +2063,7 @@ def pad(self, limit=None):
if limit is not None:
raise NotImplementedError("Does not support limit param yet.")

# Do not remove until pandas 2.0 support is added.
warnings.warn(
"pad is deprecated and will be removed in a future version. "
"Use ffill instead.",
Expand Down Expand Up @@ -2098,6 +2100,7 @@ def backfill(self, limit=None):
if limit is not None:
raise NotImplementedError("Does not support limit param yet.")

# Do not remove until pandas 2.0 support is added.
warnings.warn(
"backfill is deprecated and will be removed in a future version. "
"Use bfill instead.",
Expand Down Expand Up @@ -2278,6 +2281,7 @@ def pct_change(

if fill_method in ("pad", "backfill"):
alternative = "ffill" if fill_method == "pad" else "bfill"
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"{fill_method} is deprecated and will be removed in a future "
f"version. Use f{alternative} instead.",
Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,15 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
New RangeIndex instance with same range, casted to new dtype
"""
if dtype is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"parameter dtype is deprecated and will be removed in a "
"future version. Use the astype method instead.",
FutureWarning,
)

if names is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"parameter names is deprecated and will be removed in a "
"future version. Use the name parameter instead.",
Expand Down Expand Up @@ -554,6 +556,7 @@ def get_loc(self, key, method=None, tolerance=None):
# get_indexers method as an alternative, see
# https://github.com/rapidsai/cudf/issues/12312
if method is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"Passing method to {self.__class__.__name__}.get_loc is "
"deprecated and will raise in a future version.",
Expand Down Expand Up @@ -1128,13 +1131,15 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
New index instance, casted to new dtype
"""
if dtype is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"parameter dtype is deprecated and will be removed in a "
"future version. Use the astype method instead.",
FutureWarning,
)

if names is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"parameter names is deprecated and will be removed in a "
"future version. Use the name parameter instead.",
Expand Down Expand Up @@ -1197,6 +1202,7 @@ def get_loc(self, key, method=None, tolerance=None):
# get_indexers method as an alternative, see
# https://github.com/rapidsai/cudf/issues/12312
if method is not None:
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"Passing method to {self.__class__.__name__}.get_loc is "
"deprecated and will raise in a future version.",
Expand Down Expand Up @@ -1568,6 +1574,7 @@ class NumericIndex(GenericIndex):

@_cudf_nvtx_annotate
def __init__(self, data=None, dtype=None, copy=False, name=None):
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"cudf.{self.__class__.__name__} is deprecated and will be "
"removed from cudf in a future version. Use cudf.Index with the "
Expand Down Expand Up @@ -3065,6 +3072,7 @@ class StringIndex(GenericIndex):

@_cudf_nvtx_annotate
def __init__(self, values, copy=False, **kwargs):
# Do not remove until pandas 2.0 support is added.
warnings.warn(
f"cudf.{self.__class__.__name__} is deprecated and will be "
"removed from cudf in a future version. Use cudf.Index with the "
Expand Down
2 changes: 2 additions & 0 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ def backfill(self, value=None, axis=None, inplace=None, limit=None):
-------
Object with missing values filled or None if ``inplace=True``.
"""
# Do not remove until pandas removes this.
warnings.warn(
"DataFrame.backfill/Series.backfill is deprecated. Use "
"DataFrame.bfill/Series.bfill instead",
Expand Down Expand Up @@ -2145,6 +2146,7 @@ def pad(self, value=None, axis=None, inplace=None, limit=None):
-------
Object with missing values filled or None if ``inplace=True``.
"""
# Do not remove until pandas removes this.
warnings.warn(
"DataFrame.pad/Series.pad is deprecated. Use "
"DataFrame.ffill/Series.ffill instead",
Expand Down
1 change: 1 addition & 0 deletions python/cudf/cudf/core/join/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def _validate_merge_params(
# modified in the size 0 case.
and max(lhs._data.nlevels, 1) != max(rhs._data.nlevels, 1)
):
# Do not remove until pandas 2.0 support is added.
warnings.warn(
"merging between different levels is deprecated and will be "
f"removed in a future version. ({lhs._data.nlevels} levels on "
Expand Down
Loading

0 comments on commit 494535e

Please sign in to comment.