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 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.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Conversion
^^^^^^^^^^
- Bug in :class:`Series` construction from NumPy array with big-endian ``datetime64`` dtype (:issue:`29684`)
- Bug in :class:`Timedelta` construction with large nanoseconds keyword value (:issue:`32402`)
-
- Bug in :class:`DataFrame` construction where sets would be duplicated rather than raising (:issue:`32582`)

Strings
^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
These should not depend on core.internals.
"""

from collections import abc
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast

import numpy as np
Expand Down Expand Up @@ -446,6 +447,8 @@ def sanitize_array(
# GH#16804
arr = np.arange(data.start, data.stop, data.step, dtype="int64")
subarr = _try_cast(arr, dtype, copy, raise_cast_failure)
elif isinstance(data, abc.Set):
raise TypeError("Set type is unordered")
else:
subarr = _try_cast(data, dtype, copy, raise_cast_failure)

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2604,3 +2604,9 @@ def test_from_2d_ndarray_with_dtype(self):

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

def test_construction_from_set_raises(self):
# https://github.com/pandas-dev/pandas/issues/32582
msg = "Set type is unordered"
with pytest.raises(TypeError, match=msg):
pd.DataFrame({"a": {1, 2, 3}})