Skip to content

Commit

Permalink
TST: Check error raised when inserting wrong length categorical column (
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankarlos authored and jreback committed Nov 16, 2019
1 parent fb08cee commit 7a13fc4
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 7a13fc4

Please sign in to comment.