From a913e26f6230de6ffb97f1b32ea0f92911a3c105 Mon Sep 17 00:00:00 2001 From: vangorade Date: Fri, 1 Jan 2021 19:02:52 +0000 Subject: [PATCH 1/3] TST: add missing loc label indexing test --- pandas/tests/indexing/test_loc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 89315b16937b1..17c9104686107 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -56,9 +56,11 @@ def test_loc_getitem_label_out_of_range(self): self.check_result("loc", 20, typs=["floats"], axes=0, fails=KeyError) def test_loc_getitem_label_list(self): - # TODO: test something here? # list of labels - pass + self.check_result("loc", [0, 1, 2], typs=[ + "ints", "uints", "floats"], fails=KeyError) + self.check_result("loc", [1, 3.0, 'A'], typs=[ + "ints", "uints", "floats"], fails=KeyError) def test_loc_getitem_label_list_with_missing(self): self.check_result("loc", [0, 1, 2], typs=["empty"], fails=KeyError) From f941c09ab249252bfb6378c67084f31a07f5b29c Mon Sep 17 00:00:00 2001 From: vangorade Date: Sat, 2 Jan 2021 18:23:35 +0530 Subject: [PATCH 2/3] formated file using black --- pandas/tests/indexing/test_loc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 17c9104686107..6c5cd0f335faa 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -57,10 +57,12 @@ def test_loc_getitem_label_out_of_range(self): def test_loc_getitem_label_list(self): # list of labels - self.check_result("loc", [0, 1, 2], typs=[ - "ints", "uints", "floats"], fails=KeyError) - self.check_result("loc", [1, 3.0, 'A'], typs=[ - "ints", "uints", "floats"], fails=KeyError) + self.check_result( + "loc", [0, 1, 2], typs=["ints", "uints", "floats"], fails=KeyError + ) + self.check_result( + "loc", [1, 3.0, "A"], typs=["ints", "uints", "floats"], fails=KeyError + ) def test_loc_getitem_label_list_with_missing(self): self.check_result("loc", [0, 1, 2], typs=["empty"], fails=KeyError) From c3c7ecd7260228c03194421ef82826c6f02fc460 Mon Sep 17 00:00:00 2001 From: vangorade Date: Tue, 5 Jan 2021 14:16:13 +0530 Subject: [PATCH 3/3] TST: Added missing iloc tests --- pandas/tests/indexing/test_iloc.py | 65 ++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index bfc6b820c0fc0..24721a370241f 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -61,8 +61,8 @@ def test_iloc_getitem_list_int(self): # the correct type -class TestiLoc2: - # TODO: better name, just separating out things that dont rely on base class +class TestiLocBaseIndependent: + """Tests Independent Of Base Class""" def test_is_scalar_access(self): # GH#32085 index with duplicates doesnt matter for _is_scalar_access @@ -262,12 +262,42 @@ def test_iloc_getitem_dups(self): tm.assert_series_equal(result, expected) def test_iloc_getitem_array(self): - # TODO: test something here? - pass + df = DataFrame( + [ + {"A": 1, "B": 2, "C": 3}, + {"A": 100, "B": 200, "C": 300}, + {"A": 1000, "B": 2000, "C": 3000}, + ] + ) + + expected = DataFrame([{"A": 1, "B": 2, "C": 3}]) + tm.assert_frame_equal(df.iloc[[0]], expected) + + expected = DataFrame([{"A": 1, "B": 2, "C": 3}, {"A": 100, "B": 200, "C": 300}]) + tm.assert_frame_equal(df.iloc[[0, 1]], expected) + + expected = DataFrame([{"B": 2, "C": 3}, {"B": 2000, "C": 3000}], index=[0, 2]) + result = df.iloc[[0, 2], [1, 2]] + tm.assert_frame_equal(result, expected) def test_iloc_getitem_bool(self): - # TODO: test something here? - pass + df = DataFrame( + [ + {"A": 1, "B": 2, "C": 3}, + {"A": 100, "B": 200, "C": 300}, + {"A": 1000, "B": 2000, "C": 3000}, + ] + ) + + expected = DataFrame([{"A": 1, "B": 2, "C": 3}, {"A": 100, "B": 200, "C": 300}]) + result = df.iloc[[True, True, False]] + tm.assert_frame_equal(result, expected) + + expected = DataFrame( + [{"A": 1, "B": 2, "C": 3}, {"A": 1000, "B": 2000, "C": 3000}], index=[0, 2] + ) + result = df.iloc[lambda x: x.index % 2 == 0] + tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("index", [[True, False], [True, False, True, False]]) def test_iloc_getitem_bool_diff_len(self, index): @@ -278,8 +308,27 @@ def test_iloc_getitem_bool_diff_len(self, index): _ = s.iloc[index] def test_iloc_getitem_slice(self): - # TODO: test something here? - pass + df = DataFrame( + [ + {"A": 1, "B": 2, "C": 3}, + {"A": 100, "B": 200, "C": 300}, + {"A": 1000, "B": 2000, "C": 3000}, + ] + ) + + expected = DataFrame([{"A": 1, "B": 2, "C": 3}, {"A": 100, "B": 200, "C": 300}]) + result = df.iloc[:2] + tm.assert_frame_equal(result, expected) + + expected = DataFrame([{"A": 100, "B": 200}], index=[1]) + result = df.iloc[1:2, 0:2] + tm.assert_frame_equal(result, expected) + + expected = DataFrame( + [{"A": 1, "C": 3}, {"A": 100, "C": 300}, {"A": 1000, "C": 3000}] + ) + result = df.iloc[:, lambda df: [0, 2]] + tm.assert_frame_equal(result, expected) def test_iloc_getitem_slice_dups(self):