Skip to content

Commit

Permalink
Enforce merge validation deprecation (#13499)
Browse files Browse the repository at this point in the history
This PR raises an error when a merge is being performed between data consisting of different levels.
  • Loading branch information
galipremsagar authored Jun 3, 2023
1 parent f56ea26 commit 63b8fb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 5 additions & 7 deletions python/cudf/cudf/core/join/join.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
from __future__ import annotations

import warnings
from typing import Any, ClassVar, List, Optional

import cudf
Expand Down Expand Up @@ -422,11 +421,10 @@ def _validate_merge_params(
# modified in the size 0 case.
and max(lhs._data.nlevels, 1) != max(rhs._data.nlevels, 1)
):
warnings.warn(
"merging between different levels is deprecated and will be "
f"removed in a future version. ({lhs._data.nlevels} levels on "
f"the left, {rhs._data.nlevels} on the right)",
FutureWarning,
raise ValueError(
"Not allowed to merge between different levels. "
f"({lhs._data.nlevels} levels on "
f"the left, {rhs._data.nlevels} on the right)"
)


Expand Down
24 changes: 15 additions & 9 deletions python/cudf/cudf/tests/test_joining.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,15 +2160,21 @@ def test_join_multiindex_empty():
lhs = pd.DataFrame({"a": [1, 2, 3], "b": [2, 3, 4]}, index=["a", "b", "c"])
lhs.columns = pd.MultiIndex.from_tuples([("a", "x"), ("a", "y")])
rhs = pd.DataFrame(index=["a", "c", "d"])
with pytest.warns(FutureWarning):
expect = lhs.join(rhs, how="inner")

lhs = cudf.from_pandas(lhs)
rhs = cudf.from_pandas(rhs)
with pytest.warns(FutureWarning):
got = lhs.join(rhs, how="inner")

assert_join_results_equal(expect, got, how="inner")
g_lhs = cudf.from_pandas(lhs)
g_rhs = cudf.from_pandas(rhs)
if PANDAS_GE_200:
assert_exceptions_equal(
lfunc=lhs.join,
rfunc=g_lhs.join,
lfunc_args_and_kwargs=([rhs], {"how": "inner"}),
rfunc_args_and_kwargs=([g_rhs], {"how": "inner"}),
check_exception_type=False,
)
else:
with pytest.warns(FutureWarning):
_ = lhs.join(rhs, how="inner")
with pytest.raises(ValueError):
_ = g_lhs.join(g_rhs, how="inner")


def test_join_on_index_with_duplicate_names():
Expand Down

0 comments on commit 63b8fb1

Please sign in to comment.