Skip to content

Commit 03dffb1

Browse files
simonjayhawkinsjreback
authored andcommitted
BUG: DataFrame constructor raised ValueError with list-like data and dtype specified (#30284)
1 parent 37dfcc1 commit 03dffb1

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ ExtensionArray
862862

863863
- Bug in :class:`arrays.PandasArray` when setting a scalar string (:issue:`28118`, :issue:`28150`).
864864
- Bug where nullable integers could not be compared to strings (:issue:`28930`)
865-
-
865+
- Bug where :class:`DataFrame` constructor raised ValueError with list-like data and ``dtype`` specified (:issue:`30280`)
866866

867867

868868
Other

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):
150150

151151
index, columns = _get_axes(len(values), 1, index, columns)
152152
return arrays_to_mgr([values], columns, index, columns, dtype=dtype)
153-
elif is_extension_array_dtype(values):
153+
elif is_extension_array_dtype(values) or is_extension_array_dtype(dtype):
154154
# GH#19157
155155
if columns is None:
156156
columns = [0]

pandas/tests/extension/base/constructors.py

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def test_from_dtype(self, data):
6464
result = pd.Series(list(data), dtype=str(dtype))
6565
self.assert_series_equal(result, expected)
6666

67+
# gh-30280
68+
69+
expected = pd.DataFrame(data).astype(dtype)
70+
result = pd.DataFrame(list(data), dtype=dtype)
71+
self.assert_frame_equal(result, expected)
72+
73+
result = pd.DataFrame(list(data), dtype=str(dtype))
74+
self.assert_frame_equal(result, expected)
75+
6776
def test_pandas_array(self, data):
6877
# pd.array(extension_array) should be idempotent...
6978
result = pd.array(data)

0 commit comments

Comments
 (0)