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

More explicit index concat checking #15650

Draft
wants to merge 22 commits into
base: branch-24.06
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions python/cudf/cudf/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ def concat(objs, axis=0, join="outer", ignore_index=False, sort=None):
raise TypeError(
"when concatenating indices you must provide ONLY indices"
)
if axis == 1:
raise ValueError("cannot concatenate indices across axis 1")
er-eis marked this conversation as resolved.
Show resolved Hide resolved

only_series = all(isinstance(o, cudf.Series) for o in objs)

Expand Down
35 changes: 35 additions & 0 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1997,3 +1997,38 @@ def test_concat_dict_incorrect_type_index(d):
match="cannot concatenate a dictionary containing indices",
):
cudf.concat(d, axis=1)


@pytest.mark.parametrize(
"axis",
[
0,
pytest.param(
1,
marks=pytest.mark.xfail(
reason=("cannot concatenate indices across axis 1")
),
),
er-eis marked this conversation as resolved.
Show resolved Hide resolved
],
)
@pytest.mark.parametrize(
"idx",
[
[cudf.Index([1, 2, 3])],
[cudf.Index([1, 2, 3]), cudf.Index([4, 5, 6])],
[
cudf.MultiIndex(
levels=[[1, 2], ["blue", "red"]],
codes=[[0, 0, 1, 1], [1, 0, 1, 0]],
)
],
[cudf.CategoricalIndex([1, 2, 3])],
er-eis marked this conversation as resolved.
Show resolved Hide resolved
],
)
def test_concat_index(idx, axis):
result = cudf.concat(idx, axis=axis)
assert isinstance(result, cudf.Index)
er-eis marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(
TypeError, match="only Series and DataFrame objs are valid"
):
pd.concat([i.to_pandas() for i in idx], axis=axis)
Loading