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

Consolidate some Frame APIs #10381

Merged
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
71 changes: 32 additions & 39 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from cudf._typing import DtypeObj
from cudf.api.types import (
is_bool_dtype,
is_dtype_equal,
is_integer,
is_integer_dtype,
is_list_like,
Expand All @@ -34,6 +33,37 @@
numeric_normalize_types,
)

_index_astype_docstring = """\
Create an Index with values cast to dtypes.

The class of a new Index is determined by dtype. When conversion is
impossible, a ValueError exception is raised.

Parameters
----------
dtype : numpy dtype
Use a numpy.dtype to cast entire Index object to.
copy : bool, default False
By default, astype always returns a newly allocated object.
If copy is set to False and internal requirements on dtype are
satisfied, the original data is used to create a new Index
or the original Index is returned.

Returns
-------
Index
Index with values cast to specified dtype.

Examples
--------
>>> import cudf
>>> index = cudf.Index([1, 2, 3])
>>> index
Int64Index([1, 2, 3], dtype='int64')
>>> index.astype('float64')
Float64Index([1.0, 2.0, 3.0], dtype='float64')
"""


class BaseIndex(Serializable):
"""Base class for all cudf Index types."""
Expand Down Expand Up @@ -1200,43 +1230,6 @@ def rename(self, name, inplace=False):
out.name = name
return out

def astype(self, dtype, copy=False):
"""
Create an Index with values cast to dtypes. The class of a new Index
is determined by dtype. When conversion is impossible, a ValueError
exception is raised.

Parameters
----------
dtype : numpy dtype
Use a numpy.dtype to cast entire Index object to.
copy : bool, default False
By default, astype always returns a newly allocated object.
If copy is set to False and internal requirements on dtype are
satisfied, the original data is used to create a new Index
or the original Index is returned.

Returns
-------
Index
Index with values cast to specified dtype.

Examples
--------
>>> import cudf
>>> index = cudf.Index([1, 2, 3])
>>> index
Int64Index([1, 2, 3], dtype='int64')
>>> index.astype('float64')
Float64Index([1.0, 2.0, 3.0], dtype='float64')
"""
if is_dtype_equal(dtype, self.dtype):
return self.copy(deep=copy)

return cudf.Index(
self.copy(deep=copy)._values.astype(dtype), name=self.name
)

def to_series(self, index=None, name=None):
"""
Create a Series with both index and values equal to the index keys.
Expand Down Expand Up @@ -1278,7 +1271,7 @@ def get_slice_bound(self, label, side, kind=None):
int
Index of label.
"""
raise (NotImplementedError)
raise NotImplementedError

def __array_function__(self, func, types, args, kwargs):

Expand Down
Loading