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

Deprecate StringIndex and use Index instead #13361

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
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5853,7 +5853,7 @@ def _reduce(
)
source = self._get_columns_by_label(numeric_cols)
if source.empty:
return Series(index=cudf.StringIndex([]))
return Series(index=cudf.Index([], dtype="str"))

axis = source._get_axis_from_axis_arg(axis)

Expand Down Expand Up @@ -5895,7 +5895,7 @@ def _reduce(
)
source = self._get_columns_by_label(numeric_cols)
if source.empty:
return Series(index=cudf.StringIndex([]))
return Series(index=cudf.Index([], dtype="str"))
try:
result = [
getattr(source._data[col], op)(**kwargs)
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,9 @@ def _is_boolean(self):
class StringIndex(GenericIndex):
"""String defined indices into another Column

.. deprecated:: 23.06
`StringIndex` is deprecated, use `Index` instead.

Attributes
----------
_values: A StringColumn object or NDArray of strings
Expand All @@ -3072,6 +3075,12 @@ class StringIndex(GenericIndex):

@_cudf_nvtx_annotate
def __init__(self, values, copy=False, **kwargs):
warnings.warn(
f"cudf.{self.__class__.__name__} is deprecated and will be "
"removed from cudf in a future version. Use cudf.Index with the "
"appropriate dtype instead.",
FutureWarning,
)
kwargs = _setdefault_name(values, **kwargs)
if isinstance(values, StringColumn):
values = values.copy(deep=copy)
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,7 @@ def test_as_column_types():
assert_eq(pds, gds)

pds = pd.Series(pd.Index(["1", "18", "9"]), dtype="int")
gds = cudf.Series(cudf.StringIndex(["1", "18", "9"]), dtype="int")
gds = cudf.Series(cudf.Index(["1", "18", "9"]), dtype="int")

assert_eq(pds, gds)

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ def index(self, request):
[2, 3, 4, 1, 0, 5, 6, 8, 7, 9, 10, 13], dtype="int32"
)
elif request.param == "strindex":
return cudf.StringIndex(list(string.ascii_lowercase[:n]))
return cudf.Index(list(string.ascii_lowercase[:n]))
elif request.param == "default":
return None

Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_index_copy_datetime(name, dtype, deep=True):
@pytest.mark.parametrize("name", ["x"])
@pytest.mark.parametrize("dtype", ["category", "object"])
def test_index_copy_string(name, dtype, deep=True):
cidx = cudf.StringIndex(["a", "b", "c"])
cidx = cudf.Index(["a", "b", "c"])
pidx = cidx.to_pandas()

with pytest.warns(FutureWarning):
Expand Down Expand Up @@ -401,7 +401,7 @@ def test_index_copy_category(name, dtype, deep=True):
"idx",
[
cudf.DatetimeIndex(["2001", "2002", "2003"]),
cudf.StringIndex(["a", "b", "c"]),
cudf.Index(["a", "b", "c"]),
cudf.Index([1, 2, 3]),
cudf.Index([1.0, 2.0, 3.0]),
cudf.CategoricalIndex([1, 2, 3]),
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_rangeindex_slice_attr_name():
def test_from_pandas_str():
idx = ["a", "b", "c"]
pidx = pd.Index(idx, name="idx")
gidx_1 = cudf.StringIndex(idx, name="idx")
gidx_1 = cudf.Index(idx, name="idx")
gidx_2 = cudf.from_pandas(pidx)

assert_eq(gidx_1, gidx_2)
Expand Down
5 changes: 2 additions & 3 deletions python/cudf/cudf/tests/test_monotonic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2022, NVIDIA CORPORATION.
# Copyright (c) 2019-2023, NVIDIA CORPORATION.

"""
Tests related to is_unique and is_monotonic attributes
Expand All @@ -14,7 +14,6 @@
DatetimeIndex,
GenericIndex,
RangeIndex,
StringIndex,
)
from cudf.testing._utils import assert_eq, expect_warning_if

Expand Down Expand Up @@ -78,7 +77,7 @@ def test_generic_index(testlist):
)
def test_string_index(testlist):

index = StringIndex(testlist)
index = cudf.Index(testlist)
index_pd = pd.Index(testlist)

assert index.is_unique == index_pd.is_unique
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/tests/test_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_multiindex_swaplevel():


def test_string_index():
from cudf.core.index import StringIndex
from cudf.core.index import Index

pdf = pd.DataFrame(np.random.rand(5, 5))
gdf = cudf.from_pandas(pdf)
Expand All @@ -167,7 +167,7 @@ def test_string_index():
pdf.index = stringIndex
gdf.index = stringIndex
assert_eq(pdf, gdf)
stringIndex = StringIndex(["a", "b", "c", "d", "e"], name="name")
stringIndex = Index(["a", "b", "c", "d", "e"], name="name")
pdf.index = stringIndex.to_pandas()
gdf.index = stringIndex
assert_eq(pdf, gdf)
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ def test_string_index():
pdf.index = stringIndex
gdf.index = stringIndex
assert_eq(pdf, gdf)
stringIndex = StringIndex(["a", "b", "c", "d", "e"], name="name")
with pytest.warns(FutureWarning):
stringIndex = StringIndex(["a", "b", "c", "d", "e"], name="name")
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
pdf.index = stringIndex.to_pandas()
gdf.index = stringIndex
assert_eq(pdf, gdf)
Expand Down Expand Up @@ -2755,7 +2756,7 @@ def test_string_str_subscriptable(data, index):
assert_eq(psr.str[index], gsr.str[index])

psi = pd.Index(data)
gsi = StringIndex(data)
gsi = cudf.Index(data)

assert_eq(psi.str[index], gsi.str[index])

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_character_tokenize_index():
assert_eq(expected, actual)

sr = cudf.Index([""])
expected = cudf.StringIndex([], dtype="object")
expected = cudf.Index([], dtype="object")

actual = sr.str.character_tokenize()
assert_eq(expected, actual)
Expand Down