Skip to content

BUG: Don't multiply sets during construction #32594

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 11 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ Other
instead of ``TypeError: Can only append a Series if ignore_index=True or if the Series has a name`` (:issue:`30871`)
- Set operations on an object-dtype :class:`Index` now always return object-dtype results (:issue:`31401`)
- Bug in :meth:`AbstractHolidayCalendar.holidays` when no rules were defined (:issue:`31415`)
- Bug in :class:`DataFrame` expanding sets when passed to the constructor (:issue:`32582`)

.. ---------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ def sanitize_array(
subarr = subarr.copy()
return subarr

elif isinstance(data, (list, tuple)) and len(data) > 0:
elif isinstance(data, (list, tuple, set)) and len(data) > 0:
if isinstance(data, set):
data = list(data)
if dtype is not None:
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
else:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2609,3 +2609,10 @@ def test_from_2d_ndarray_with_dtype(self):

expected = pd.DataFrame(array_dim2).astype("datetime64[ns, UTC]")
tm.assert_frame_equal(df, expected)

def test_construction_from_set(self):
# https://github.com/pandas-dev/pandas/issues/32582
result = pd.DataFrame({"a": {1, 2, 3}})
expected = pd.DataFrame({"a": [1, 2, 3]})

tm.assert_frame_equal(result, expected)