Skip to content

Commit 6d7b1c5

Browse files
authored
Slicing columns with mixed types <str>,<int> fails with ValueError #20975 (#38717)
1 parent e4f35f4 commit 6d7b1c5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/tests/indexing/test_loc.py

+8
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,14 @@ def test_loc_getitem_slice_labels_int_in_object_index(self, frame_or_series, val
16441644
expected = frame_or_series(range(4), index=[value, "first", 2, "third"])
16451645
tm.assert_equal(result, expected)
16461646

1647+
def test_loc_getitem_slice_columns_mixed_dtype(self):
1648+
# GH: 20975
1649+
df = DataFrame({"test": 1, 1: 2, 2: 3}, index=[0])
1650+
expected = DataFrame(
1651+
data=[[2, 3]], index=[0], columns=pd.Index([1, 2], dtype=object)
1652+
)
1653+
tm.assert_frame_equal(df.loc[:, 1:], expected)
1654+
16471655

16481656
class TestLocBooleanMask:
16491657
def test_loc_setitem_bool_mask_timedeltaindex(self):

0 commit comments

Comments
 (0)