Skip to content

Commit 466a9ba

Browse files
committed
BUG: Create empty dataframe with string dtype fails
1 parent 3d4f9dc commit 466a9ba

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/internals/construction.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ def init_dict(data, index, columns, dtype=None):
242242

243243
# no obvious "empty" int column
244244
if missing.any() and not is_integer_dtype(dtype):
245-
if dtype is None or np.issubdtype(dtype, np.flexible):
245+
if is_dtype_equal(dtype, "string"):
246+
# GH33623
247+
nan_dtype = dtype
248+
elif dtype is None or np.issubdtype(dtype, np.flexible):
246249
# GH#1783
247250
nan_dtype = object
248251
else:

pandas/tests/frame/test_constructors.py

+4
Original file line numberDiff line numberDiff line change
@@ -2679,3 +2679,7 @@ def test_construction_from_set_raises(self):
26792679
msg = "Set type is unordered"
26802680
with pytest.raises(TypeError, match=msg):
26812681
pd.DataFrame({"a": {1, 2, 3}})
2682+
2683+
def test_construct_empty_dataframe_with_string_dtype(self):
2684+
# GH 33623
2685+
pd.DataFrame(columns=["a"], dtype="string")

0 commit comments

Comments
 (0)