Skip to content

Commit

Permalink
BUG: Raise ValueError instead of bare Exception in sanitize_array (pa…
Browse files Browse the repository at this point in the history
  • Loading branch information
micahjsmith authored and jbrockmendel committed Oct 10, 2020
1 parent 04d33b8 commit 8912516
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ Other
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
- Fixed metadata propagation in the :class:`Series.dt` accessor (:issue:`28283`)
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
- 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`)

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def sanitize_array(

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def test_constructor(self, datetime_series):
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
assert not Series().index._is_all_dates

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

mixed.name = "Series"
Expand Down

0 comments on commit 8912516

Please sign in to comment.