Skip to content

Commit 2c30222

Browse files
authored
BUG: Raise ValueError instead of bare Exception in sanitize_array (#35769)
1 parent c540329 commit 2c30222

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Other
476476
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
477477
- Fixed metadata propagation in the :class:`Series.dt` accessor (:issue:`28283`)
478478
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
479+
- Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`)
479480

480481
.. ---------------------------------------------------------------------------
481482

pandas/core/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def sanitize_array(
510510

511511
elif subarr.ndim > 1:
512512
if isinstance(data, np.ndarray):
513-
raise Exception("Data must be 1-dimensional")
513+
raise ValueError("Data must be 1-dimensional")
514514
else:
515515
subarr = com.asarray_tuplesafe(data, dtype=dtype)
516516

pandas/tests/series/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def test_constructor(self, datetime_series):
113113
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
114114
assert not Series().index._is_all_dates
115115

116-
# exception raised is of type Exception
117-
with pytest.raises(Exception, match="Data must be 1-dimensional"):
116+
# exception raised is of type ValueError GH35744
117+
with pytest.raises(ValueError, match="Data must be 1-dimensional"):
118118
Series(np.random.randn(3, 3), index=np.arange(3))
119119

120120
mixed.name = "Series"

0 commit comments

Comments
 (0)