Skip to content

Commit a23c7d6

Browse files
committed
Check error raised with wrong length cat insertion
1 parent e5c3907 commit a23c7d6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/tests/frame/test_dtypes.py

+7
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,13 @@ def test_astype_duplicate_col(self):
724724
expected = concat([a1_str, b, a2_str], axis=1)
725725
tm.assert_frame_equal(result, expected)
726726

727+
def test_wrong_length_cat_dtype_raises(self):
728+
cat = pd.Categorical.from_codes([0, 1, 1, 0, 1, 2], ["a", "b", "c"])
729+
df = pd.DataFrame({"bar": range(10)})
730+
err = "Length of values does not match length of index"
731+
with pytest.raises(ValueError, match=err):
732+
df["foo"] = cat
733+
727734
@pytest.mark.parametrize(
728735
"dtype",
729736
[

0 commit comments

Comments
 (0)