Skip to content

Commit 74f6579

Browse files
authored
BUG: Don't multiply sets during construction (#32594)
1 parent 74c5306 commit 74f6579

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Conversion
274274
^^^^^^^^^^
275275
- Bug in :class:`Series` construction from NumPy array with big-endian ``datetime64`` dtype (:issue:`29684`)
276276
- Bug in :class:`Timedelta` construction with large nanoseconds keyword value (:issue:`32402`)
277-
-
277+
- Bug in :class:`DataFrame` construction where sets would be duplicated rather than raising (:issue:`32582`)
278278

279279
Strings
280280
^^^^^^^

pandas/core/construction.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
These should not depend on core.internals.
66
"""
77

8+
from collections import abc
89
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast
910

1011
import numpy as np
@@ -446,6 +447,8 @@ def sanitize_array(
446447
# GH#16804
447448
arr = np.arange(data.start, data.stop, data.step, dtype="int64")
448449
subarr = _try_cast(arr, dtype, copy, raise_cast_failure)
450+
elif isinstance(data, abc.Set):
451+
raise TypeError("Set type is unordered")
449452
else:
450453
subarr = _try_cast(data, dtype, copy, raise_cast_failure)
451454

pandas/tests/frame/test_constructors.py

+6
Original file line numberDiff line numberDiff line change
@@ -2604,3 +2604,9 @@ def test_from_2d_ndarray_with_dtype(self):
26042604

26052605
expected = DataFrame(array_dim2).astype("datetime64[ns, UTC]")
26062606
tm.assert_frame_equal(df, expected)
2607+
2608+
def test_construction_from_set_raises(self):
2609+
# https://github.com/pandas-dev/pandas/issues/32582
2610+
msg = "Set type is unordered"
2611+
with pytest.raises(TypeError, match=msg):
2612+
pd.DataFrame({"a": {1, 2, 3}})

0 commit comments

Comments
 (0)