diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 3126b9d9d3e2e..51535db9208a0 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -223,7 +223,9 @@ def init_dict(data, index, columns, dtype=None): # no obvious "empty" int column if missing.any() and not is_integer_dtype(dtype): - if dtype is None or np.issubdtype(dtype, np.flexible): + if is_categorical_dtype(dtype): + nan_dtype = dtype + elif dtype is None or np.issubdtype(dtype, np.flexible): # GH#1783 nan_dtype = object else: diff --git a/pandas/tests/frame/test_dtypes.py b/pandas/tests/frame/test_dtypes.py index 00be13b1c0e72..aa0bc21ec78ee 100644 --- a/pandas/tests/frame/test_dtypes.py +++ b/pandas/tests/frame/test_dtypes.py @@ -69,6 +69,10 @@ def test_empty_frame_dtypes_ftypes(self): norows_df = pd.DataFrame(columns=list("abc")) assert_series_equal(norows_df.dtypes, pd.Series(np.object, index=list("abc"))) + cat = pd.CategoricalDtype() + norows_cat_df = pd.DataFrame(columns=list("abc"), dtype=cat) + assert_series_equal(norows_cat_df.dtypes, pd.Series(cat, index=list("abc"))) + # GH 26705 - Assert .ftypes is deprecated with tm.assert_produces_warning(FutureWarning): assert_series_equal(