Skip to content

Commit 7a13fc4

Browse files
ryankarlosjreback
authored andcommitted
TST: Check error raised when inserting wrong length categorical column (#29523)
1 parent fb08cee commit 7a13fc4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/tests/frame/test_indexing.py

+8
Original file line numberDiff line numberDiff line change
@@ -3881,3 +3881,11 @@ def test_loc_indexing_preserves_index_category_dtype(self):
38813881

38823882
result = df.loc[["a"]].index.levels[0]
38833883
tm.assert_index_equal(result, expected)
3884+
3885+
def test_wrong_length_cat_dtype_raises(self):
3886+
# GH29523
3887+
cat = pd.Categorical.from_codes([0, 1, 1, 0, 1, 2], ["a", "b", "c"])
3888+
df = pd.DataFrame({"bar": range(10)})
3889+
err = "Length of values does not match length of index"
3890+
with pytest.raises(ValueError, match=err):
3891+
df["foo"] = cat

0 commit comments

Comments
 (0)