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

Align MultiIndex.get_indexder with pandas 2.2 change #15059

Merged
merged 11 commits into from
Feb 21, 2024
6 changes: 6 additions & 0 deletions python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,12 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
result_series = cudf.Series(result)

if method in {"ffill", "bfill", "pad", "backfill"}:
if not (
self.is_monotonic_increasing or self.is_monotonic_decreasing
):
raise ValueError(
"index must be monotonic increasing or decreasing"
)
result_series = _get_indexer_basic(
index=self,
positions=result_series,
Expand Down
34 changes: 18 additions & 16 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,14 +2067,6 @@ def test_get_loc_multi_numeric_deviate(idx, key, result):
assert_eq(expected, got)


@pytest.mark.parametrize(
"idx",
[
pd.MultiIndex.from_tuples(
[(2, 1, 1), (1, 2, 3), (1, 2, 1), (1, 1, 10), (1, 1, 1), (2, 2, 1)]
)
],
)
@pytest.mark.parametrize(
"key",
[
Expand All @@ -2084,19 +2076,29 @@ def test_get_loc_multi_numeric_deviate(idx, key, result):
],
)
@pytest.mark.parametrize("method", [None, "ffill", "bfill"])
def test_get_indexer_multi_numeric_deviate(request, idx, key, method):
pi = idx
def test_get_indexer_multi_numeric_deviate(request, key, method):
pi = pd.MultiIndex.from_tuples(
[(2, 1, 1), (1, 2, 3), (1, 2, 1), (1, 1, 10), (1, 1, 1), (2, 2, 1)]
)
gi = cudf.from_pandas(pi)
request.applymarker(
pytest.mark.xfail(
condition=method is not None and key == ((1, 2, 3),),
condition=method is not None
and key == ((1, 2, 3),)
and not PANDAS_GE_220,
reason="https://github.com/pandas-dev/pandas/issues/53452",
)
)
expected = pi.get_indexer(key, method=method)
got = gi.get_indexer(key, method=method)

assert_eq(expected, got)
if method is not None:
with pytest.raises(ValueError):
gi.get_indexer(key, method=method)
if PANDAS_GE_220:
with pytest.raises(ValueError):
pi.get_indexer(key, method=method)
else:
got = gi.get_indexer(key, method=method)
expected = pi.get_indexer(key, method=method)
assert_eq(got, expected)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -3094,7 +3096,7 @@ def test_index_with_index_dtype(data, dtype):


def test_period_index_error():
pidx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])
pidx = pd.PeriodIndex(data=[pd.Period("2020-01")])
with pytest.raises(NotImplementedError):
cudf.from_pandas(pidx)
with pytest.raises(NotImplementedError):
Expand Down