From 45256cae087b7eda3f3248039caedbb3e89a6de5 Mon Sep 17 00:00:00 2001 From: Calvin Ho <18680207+calvh@users.noreply.github.com> Date: Wed, 14 Jul 2021 00:49:52 -0400 Subject: [PATCH] TST: Test reindex w/ multiindex df (GH21247) Should throw ValueError --- pandas/tests/indexes/multi/test_reindex.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pandas/tests/indexes/multi/test_reindex.py b/pandas/tests/indexes/multi/test_reindex.py index d9c77c5bdcd60..340b546125d8d 100644 --- a/pandas/tests/indexes/multi/test_reindex.py +++ b/pandas/tests/indexes/multi/test_reindex.py @@ -133,3 +133,31 @@ def test_reindex_not_all_tuples(): tm.assert_index_equal(res, idx) expected = np.array([0, 1, 2, -1], dtype=np.intp) tm.assert_numpy_array_equal(indexer, expected) + + +def test_reindex_limit_arg_with_multiindex(): + # GH21247 + + idx = MultiIndex.from_tuples([(3, "A"), (4, "A"), (4, "B")]) + + df = pd.Series([0.02, 0.01, 0.012], index=idx) + + new_idx = MultiIndex.from_tuples( + [ + (3, "A"), + (3, "B"), + (4, "A"), + (4, "B"), + (4, "C"), + (5, "B"), + (5, "C"), + (6, "B"), + (6, "C"), + ] + ) + + with pytest.raises( + ValueError, + match="limit argument only valid if doing pad, backfill or nearest reindexing", + ): + df.reindex(new_idx, fill_value=0, limit=1)