Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3881,3 +3881,11 @@ def test_loc_indexing_preserves_index_category_dtype(self):

result = df.loc[["a"]].index.levels[0]
tm.assert_index_equal(result, expected)

def test_wrong_length_cat_dtype_raises(self):
# GH29523
cat = pd.Categorical.from_codes([0, 1, 1, 0, 1, 2], ["a", "b", "c"])
df = pd.DataFrame({"bar": range(10)})
err = "Length of values does not match length of index"
with pytest.raises(ValueError, match=err):
df["foo"] = cat