From eb2d97711341f2b76ef441c97e67fac8297d23a0 Mon Sep 17 00:00:00 2001 From: Eric Leerssen Date: Sat, 10 Apr 2021 17:07:49 +0200 Subject: [PATCH 1/2] TST Add test for iloc on interval index --- pandas/tests/indexing/test_iloc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index e2a063a7697d9..7b30549ab8099 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -17,6 +17,7 @@ CategoricalDtype, DataFrame, Index, + Interval, NaT, Series, array, @@ -1092,6 +1093,23 @@ def test_iloc_getitem_with_duplicates2(self): expected = df.take([0], axis=1) tm.assert_frame_equal(result, expected) + def test_iloc_getitem_interval(self): + # GH#17130 + df = DataFrame({Interval(1, 2): [1, 2]}) + + result = df.iloc[0] + expected = Series({Interval(1, 2): 1}, name=0) + tm.assert_series_equal(result, expected) + + result = df.iloc[:, 0] + expected = Series([1, 2], name=Interval(1, 2)) + tm.assert_series_equal(result, expected) + + result = df.copy() + result.iloc[:, 0] += 1 + expected = DataFrame({Interval(1, 2): [2, 3]}) + tm.assert_frame_equal(result, expected) + class TestILocErrors: # NB: this test should work for _any_ Series we can pass as From dabab045d6e8617c04c2610e437b64036b25dd58 Mon Sep 17 00:00:00 2001 From: Eric Leerssen Date: Sun, 11 Apr 2021 22:29:55 +0200 Subject: [PATCH 2/2] TST Update test name --- pandas/tests/indexing/test_iloc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 7b30549ab8099..853c7079a3c1b 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -1093,7 +1093,7 @@ def test_iloc_getitem_with_duplicates2(self): expected = df.take([0], axis=1) tm.assert_frame_equal(result, expected) - def test_iloc_getitem_interval(self): + def test_iloc_interval(self): # GH#17130 df = DataFrame({Interval(1, 2): [1, 2]})