Skip to content

Commit 5c8ae20

Browse files
ryankarlosproost
authored andcommitted
TST:Add test to check single category col returns series with single row slice (pandas-dev#29521)
Closes pandas-dev#14011
1 parent 7326eee commit 5c8ae20

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pandas/tests/frame/test_dtypes.py

+9
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,15 @@ def test_astype_categoricaldtype_class_raises(self, cls):
762762
with pytest.raises(TypeError, match=xpr):
763763
df["A"].astype(cls)
764764

765+
def test_singlerow_slice_categoricaldtype_gives_series(self):
766+
# GH29521
767+
df = pd.DataFrame({"x": pd.Categorical("a b c d e".split())})
768+
result = df.iloc[0]
769+
raw_cat = pd.Categorical(["a"], categories=["a", "b", "c", "d", "e"])
770+
expected = pd.Series(raw_cat, index=["x"], name=0, dtype="category")
771+
772+
tm.assert_series_equal(result, expected)
773+
765774
@pytest.mark.parametrize("dtype", ["Int64", "Int32", "Int16"])
766775
def test_astype_extension_dtypes(self, dtype):
767776
# GH 22578

0 commit comments

Comments
 (0)