Skip to content

Commit

Permalink
Align Index __init__ APIs with pandas 2.x (#16362)
Browse files Browse the repository at this point in the history
* It would be nice to have `Index`'s constructor to not go through `IndexMeta.__call__`, but I think that would be a separate effort
* There were a couple `verify_integrity` keyword arguments added that don't raise a `NotImplementedError` since there's not support, but I don't think it's worth making this case falling back in `cudf.pandas` as it's just a validation and won't affect further behavior with the object

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

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

URL: #16362
  • Loading branch information
mroeschke authored Jul 24, 2024
1 parent 743264f commit 7191b74
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/cudf/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def on_missing_reference(app, env, node, contnode):
("py:class", "Dtype"),
# The following are erroneously warned due to
# https://github.com/sphinx-doc/sphinx/issues/11225
("py:obj", "cudf.Index.values_host"),
("py:class", "pa.Array"),
("py:class", "ScalarLike"),
("py:class", "ParentType"),
Expand Down
48 changes: 37 additions & 11 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class IndexMeta(type):
"""Custom metaclass for Index that overrides instance/subclass tests."""

def __call__(cls, data, *args, **kwargs):
if kwargs.get("tupleize_cols", True) is not True:
raise NotImplementedError(
"tupleize_cols is currently not supported."
)

if cls is Index:
return as_index(
arbitrary=data,
Expand Down Expand Up @@ -997,21 +1002,23 @@ def __dask_tokenize__(self):

class Index(SingleColumnFrame, BaseIndex, metaclass=IndexMeta):
"""
An array of orderable values that represent the indices of another Column
Immutable sequence used for indexing and alignment.
Attributes
----------
_values: A Column object
name: A string
The basic object storing axis labels for all pandas objects.
Parameters
----------
data : Column
The Column of data for this index
name : str optional
The name of the Index. If not provided, the Index adopts the value
Column's name. Otherwise if this name is different from the value
Column's, the data Column will be cloned to adopt this name.
data : array-like (1-dimensional)
dtype : str, numpy.dtype, or ExtensionDtype, optional
Data type for the output Index. If not specified, this will be
inferred from `data`.
copy : bool, default False
Copy input data.
name : object
Name to be stored in the index.
tupleize_cols : bool (default: True)
When True, attempt to create a MultiIndex if possible.
Currently not supported.
"""

@_performance_tracking
Expand Down Expand Up @@ -1735,8 +1742,18 @@ def __init__(
if tz is not None:
raise NotImplementedError("tz is not yet supported")
if normalize is not False:
warnings.warn(
"The 'normalize' keyword is "
"deprecated and will be removed in a future version. ",
FutureWarning,
)
raise NotImplementedError("normalize == True is not yet supported")
if closed is not None:
warnings.warn(
"The 'closed' keyword is "
"deprecated and will be removed in a future version. ",
FutureWarning,
)
raise NotImplementedError("closed is not yet supported")
if ambiguous != "raise":
raise NotImplementedError("ambiguous is not yet supported")
Expand Down Expand Up @@ -2480,6 +2497,14 @@ def __init__(
if freq is not None:
raise NotImplementedError("freq is not yet supported")

if closed is not None:
warnings.warn(
"The 'closed' keyword is "
"deprecated and will be removed in a future version. ",
FutureWarning,
)
raise NotImplementedError("closed is not yet supported")

if unit is not None:
warnings.warn(
"The 'unit' keyword is "
Expand Down Expand Up @@ -2863,6 +2888,7 @@ def __init__(
dtype=None,
copy: bool = False,
name=None,
verify_integrity: bool = True,
):
name = _getdefault_name(data, name=name)

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(
dtype=None,
copy=False,
name=None,
**kwargs,
verify_integrity=True,
):
if sortorder is not None:
raise NotImplementedError("sortorder is not yet supported")
Expand Down

0 comments on commit 7191b74

Please sign in to comment.