Skip to content

TST: add missing iloc label indexing tests #38967

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

Merged
merged 5 commits into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 57 additions & 8 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):

Expand Down