Skip to content

Commit a87f059

Browse files
simonjayhawkinsquintusdias
authored andcommitted
TST: label-based indexing fails with certain list indexers in case of mixed integers/strings columns names (pandas-dev#27537)
1 parent 8320c7f commit a87f059

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/indexing/test_loc.py

+18
Original file line numberDiff line numberDiff line change
@@ -1081,3 +1081,21 @@ def test_series_loc_getitem_label_list_missing_values():
10811081
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
10821082
result = s.loc[key]
10831083
tm.assert_series_equal(result, expected)
1084+
1085+
1086+
@pytest.mark.parametrize(
1087+
"columns, column_key, expected_columns, check_column_type",
1088+
[
1089+
([2011, 2012, 2013], [2011, 2012], [0, 1], True),
1090+
([2011, 2012, "All"], [2011, 2012], [0, 1], False),
1091+
([2011, 2012, "All"], [2011, "All"], [0, 2], True),
1092+
],
1093+
)
1094+
def test_loc_getitem_label_list_integer_labels(
1095+
columns, column_key, expected_columns, check_column_type
1096+
):
1097+
# gh-14836
1098+
df = DataFrame(np.random.rand(3, 3), columns=columns, index=list("ABC"))
1099+
expected = df.iloc[:, expected_columns]
1100+
result = df.loc[["A", "B", "C"], column_key]
1101+
tm.assert_frame_equal(result, expected, check_column_type=check_column_type)

0 commit comments

Comments
 (0)