Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Deprecate names & dtype in Index.copy #12825

Merged
merged 6 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2023, NVIDIA CORPORATION.

from __future__ import annotations

Expand Down Expand Up @@ -313,9 +313,20 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
Ignored for RangeIndex
dtype : numpy dtype optional (default: None)
Target dtype for underlying range data

.. deprecated:: 23.02
vyasr marked this conversation as resolved.
Show resolved Hide resolved

The `dtype` parameter is deprecated and will be removed in
a future version of cudf. Use the `astype` method instead.

names : list-like optional (default: False)
Kept compatibility with MultiIndex. Should not be used.

.. deprecated:: 23.04

The parameter `names` is deprecated and will be removed in
a future version of cudf. Use the `name` parameter instead.

Returns
-------
New RangeIndex instance with same range, casted to new dtype
Expand All @@ -327,6 +338,13 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
FutureWarning,
)

if names is not None:
warnings.warn(
"parameter names is deprecated and will be removed in a "
"future version. Use the name parameter instead.",
FutureWarning,
)

dtype = self.dtype if dtype is None else dtype

if not np.issubdtype(dtype, np.signedinteger):
Expand Down Expand Up @@ -1135,9 +1153,20 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
With ``deep=False`` the original data is used
dtype : numpy dtype, default None
Target datatype to cast into, use original dtype when None

.. deprecated:: 23.02

The `dtype` parameter is deprecated and will be removed in
a future version of cudf. Use the `astype` method instead.

names : list-like, default False
Kept compatibility with MultiIndex. Should not be used.

.. deprecated:: 23.04

The parameter `names` is deprecated and will be removed in
a future version of cudf. Use the `name` parameter instead.

Returns
-------
New index instance, casted to new dtype
Expand All @@ -1149,6 +1178,13 @@ def copy(self, name=None, deep=False, dtype=None, names=None):
FutureWarning,
)

if names is not None:
warnings.warn(
"parameter names is deprecated and will be removed in a "
"future version. Use the name parameter instead.",
FutureWarning,
)

dtype = self.dtype if dtype is None else dtype
name = self.name if name is None else name

Expand Down
25 changes: 25 additions & 0 deletions python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,29 @@ def copy(
Names for each of the index levels.
dtype : object, optional (default None)
MultiIndex dtype, only supports None or object type

.. deprecated:: 23.02

The `dtype` parameter is deprecated and will be removed in
a future version of cudf. Use the `astype` method instead.

levels : sequence of arrays, optional (default None)
The unique labels for each level. Original values used if None.

.. deprecated:: 23.02

The `levels` parameter is deprecated and will be removed in
a future version of cudf.

codes : sequence of arrays, optional (default None)
Integers for each level designating which label at each location.
Original values used if None.

.. deprecated:: 23.02

The `codes` parameter is deprecated and will be removed in
a future version of cudf.

deep : Bool (default False)
If True, `._data`, `._levels`, `._codes` will be copied. Ignored if
`levels` or `codes` are specified.
Expand Down Expand Up @@ -401,6 +419,13 @@ def copy(
FutureWarning,
)

if dtype is not None:
warnings.warn(
"parameter dtype is deprecated and will be removed in a "
"future version. Use the astype method instead.",
FutureWarning,
)

dtype = object if dtype is None else dtype
if not pd.core.dtypes.common.is_object_dtype(dtype):
raise TypeError("Dtype for MultiIndex only supports object type.")
Expand Down