Skip to content

Commit fab911a

Browse files
authored
Align MultiIndex.get_indexder with pandas 2.2 change (#15059)
Aligns with pandas-dev/pandas#55352 Additionally, refactored a `pandas.PeriodIndex` usage to a non-deprecated version Authors: - Matthew Roeschke (https://github.com/mroeschke) - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: #15059
1 parent e7a7e48 commit fab911a

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

python/cudf/cudf/core/multiindex.py

+6
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,12 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
18361836
raise NotImplementedError(
18371837
f"{method=} is not supported yet for MultiIndex."
18381838
)
1839+
if method in {"ffill", "bfill", "pad", "backfill"} and not (
1840+
self.is_monotonic_increasing or self.is_monotonic_decreasing
1841+
):
1842+
raise ValueError(
1843+
"index must be monotonic increasing or decreasing"
1844+
)
18391845

18401846
result = cudf.core.column.full(
18411847
len(target),

python/cudf/cudf/tests/test_index.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -2067,14 +2067,6 @@ def test_get_loc_multi_numeric_deviate(idx, key, result):
20672067
assert_eq(expected, got)
20682068

20692069

2070-
@pytest.mark.parametrize(
2071-
"idx",
2072-
[
2073-
pd.MultiIndex.from_tuples(
2074-
[(2, 1, 1), (1, 2, 3), (1, 2, 1), (1, 1, 10), (1, 1, 1), (2, 2, 1)]
2075-
)
2076-
],
2077-
)
20782070
@pytest.mark.parametrize(
20792071
"key",
20802072
[
@@ -2084,21 +2076,42 @@ def test_get_loc_multi_numeric_deviate(idx, key, result):
20842076
],
20852077
)
20862078
@pytest.mark.parametrize("method", [None, "ffill", "bfill"])
2087-
def test_get_indexer_multi_numeric_deviate(request, idx, key, method):
2088-
pi = idx
2079+
def test_get_indexer_multi_numeric_deviate(key, method):
2080+
pi = pd.MultiIndex.from_tuples(
2081+
[(2, 1, 1), (1, 2, 3), (1, 2, 1), (1, 1, 10), (1, 1, 1), (2, 2, 1)]
2082+
).sort_values()
20892083
gi = cudf.from_pandas(pi)
2090-
request.applymarker(
2091-
pytest.mark.xfail(
2092-
condition=method is not None and key == ((1, 2, 3),),
2093-
reason="https://github.com/pandas-dev/pandas/issues/53452",
2094-
)
2095-
)
2084+
20962085
expected = pi.get_indexer(key, method=method)
20972086
got = gi.get_indexer(key, method=method)
20982087

20992088
assert_eq(expected, got)
21002089

21012090

2091+
@pytest.mark.xfail(
2092+
not PANDAS_GE_220, reason="Remove after pandas-2.2+ upgrade"
2093+
)
2094+
@pytest.mark.parametrize("method", ["ffill", "bfill"])
2095+
def test_get_indexer_multi_error(method):
2096+
pi = pd.MultiIndex.from_tuples(
2097+
[(2, 1, 1), (1, 2, 3), (1, 2, 1), (1, 1, 10), (1, 1, 1), (2, 2, 1)]
2098+
)
2099+
gi = cudf.from_pandas(pi)
2100+
2101+
assert_exceptions_equal(
2102+
pi.get_indexer,
2103+
gi.get_indexer,
2104+
lfunc_args_and_kwargs=(
2105+
[],
2106+
{"target": ((1, 2, 3),), "method": method},
2107+
),
2108+
rfunc_args_and_kwargs=(
2109+
[],
2110+
{"target": ((1, 2, 3),), "method": method},
2111+
),
2112+
)
2113+
2114+
21022115
@pytest.mark.parametrize(
21032116
"idx",
21042117
[
@@ -3094,7 +3107,7 @@ def test_index_with_index_dtype(data, dtype):
30943107

30953108

30963109
def test_period_index_error():
3097-
pidx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])
3110+
pidx = pd.PeriodIndex(data=[pd.Period("2020-01")])
30983111
with pytest.raises(NotImplementedError):
30993112
cudf.from_pandas(pidx)
31003113
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)