Skip to content

Commit

Permalink
Deprecate various functions that don't need to be defined for Index. (#…
Browse files Browse the repository at this point in the history
…10647)

This PR adds deprecations for various `Frame` methods that shouldn't actually be defined for `Index` objects. These methods can all be moved down to `IndexedFrame` in 22.08. This change contributes to making a clean distinction between `Frame` and `IndexedFrame`.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

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

URL: #10647
  • Loading branch information
vyasr authored Apr 13, 2022
1 parent ce56bc3 commit 489e41f
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ def scatter_by_map(
-------
A list of cudf.DataFrame objects.
"""
if not isinstance(self, cudf.DataFrame):
warnings.warn(
f"{self.__class__.__name__}.scatter_by_map is deprecated and "
"will be removed.",
FutureWarning,
)

# map_index might be a column name or array,
# make it a Column
Expand Down Expand Up @@ -1095,6 +1101,8 @@ def fillna(
elif method == "backfill":
method = "bfill"

# TODO: This logic should be handled in different subclasses since
# different Frames support different types of values.
if isinstance(value, cudf.Series):
value = value.reindex(self._data.names)
elif isinstance(value, cudf.DataFrame):
Expand Down Expand Up @@ -1209,6 +1217,11 @@ def interpolate(
some or all ``NaN`` values
"""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
"Index.interpolate is deprecated and will be removed.",
FutureWarning,
)

if method in {"pad", "ffill"} and limit_direction != "forward":
raise ValueError(
Expand Down Expand Up @@ -1320,6 +1333,12 @@ def rank(
same type as caller
Return a Series or DataFrame with data ranks as values.
"""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
"Index.rank is deprecated and will be removed.",
FutureWarning,
)

if method not in {"average", "min", "max", "first", "dense"}:
raise KeyError(method)

Expand Down Expand Up @@ -1355,6 +1374,12 @@ def rank(
@_cudf_nvtx_annotate
def shift(self, periods=1, freq=None, axis=0, fill_value=None):
"""Shift values by `periods` positions."""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
"Index.shift is deprecated and will be removed.",
FutureWarning,
)

axis = self._get_axis_from_axis_arg(axis)
if axis != 0:
raise ValueError("Only axis=0 is supported.")
Expand Down Expand Up @@ -1747,6 +1772,12 @@ def replace(
3 3 8 d
4 4 9 e
"""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
"Index.replace is deprecated and will be removed.",
FutureWarning,
)

if limit is not None:
raise NotImplementedError("limit parameter is not implemented yet")

Expand Down Expand Up @@ -2309,6 +2340,12 @@ def scale(self):
4 0.043478
dtype: float64
"""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
"Index.scale is deprecated and will be removed.",
FutureWarning,
)

vmin = self.min()
vmax = self.max()
scaled = (self - vmin) / (vmax - vmin)
Expand Down Expand Up @@ -3365,6 +3402,12 @@ def _scan(self, op, axis=None, skipna=True):
2 6 24
3 10 34
"""
if isinstance(self, cudf.BaseIndex):
warnings.warn(
f"Index.{op} is deprecated and will be removed.",
FutureWarning,
)

cast_to_int = op in ("cumsum", "cumprod")
skipna = True if skipna is None else skipna

Expand Down Expand Up @@ -3402,7 +3445,7 @@ def _scan(self, op, axis=None, skipna=True):
# TODO: This will work for Index because it's passing self._index
# (which is None), but eventually we may want to remove that parameter
# for Index._from_data and simplify.
return self._from_data(results, index=self._index)
return self._from_data(results, self._index)

@_cudf_nvtx_annotate
@ioutils.doc_to_json()
Expand Down

0 comments on commit 489e41f

Please sign in to comment.