Skip to content

BUG: DataFrame constructor raised ValueError with list-like data and … #30284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ ExtensionArray

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


Other
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):

index, columns = _get_axes(len(values), 1, index, columns)
return arrays_to_mgr([values], columns, index, columns, dtype=dtype)
elif is_extension_array_dtype(values):
elif is_extension_array_dtype(values) or is_extension_array_dtype(dtype):
# GH#19157
if columns is None:
columns = [0]
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/base/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ def test_from_dtype(self, data):
result = pd.Series(list(data), dtype=str(dtype))
self.assert_series_equal(result, expected)

# gh-30280

expected = pd.DataFrame(data).astype(dtype)
result = pd.DataFrame(list(data), dtype=dtype)
self.assert_frame_equal(result, expected)

result = pd.DataFrame(list(data), dtype=str(dtype))
self.assert_frame_equal(result, expected)

def test_pandas_array(self, data):
# pd.array(extension_array) should be idempotent...
result = pd.array(data)
Expand Down