From 822bc8f35b206e927a599b77973c327d8b11da4d Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Sun, 16 Aug 2020 19:17:49 -0400 Subject: [PATCH 1/5] Raise ValueError instead of bare Exception --- pandas/core/construction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 47f10f1f65f4a..c1e33b7177ce4 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -489,7 +489,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) From 50e51fd2fa87d59e72aa9bb19a675aad934332a7 Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Thu, 24 Sep 2020 14:44:39 -0400 Subject: [PATCH 2/5] Update test --- pandas/tests/series/test_constructors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 1dd410ad02ee0..34cbadde3a619 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -106,8 +106,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" From 72bd0912c816403cd9f955d96397d16882d30071 Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Thu, 24 Sep 2020 19:05:43 +0000 Subject: [PATCH 3/5] Add whatsnew entry --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 42f95d88d74ac..3d915a6b41835 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -275,7 +275,7 @@ ExtensionArray Other ^^^^^ -- +- Bug in :meth:`pandas.core.construction.sanitize_array` in which passing a >1d array to the :class:`Series` constructor raises a bare ``Exception``. Now raises a ``ValueError`` (:issue:`35744`) - .. --------------------------------------------------------------------------- From 65a68f6ac25df221cb58e55ecdef64740f00f15e Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Thu, 24 Sep 2020 15:18:22 -0400 Subject: [PATCH 4/5] Add back newline --- doc/source/whatsnew/v1.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 978c36665a3f4..1b108fdf7c225 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -373,6 +373,7 @@ ExtensionArray Other ^^^^^ + - Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` incorrectly raising ``AssertionError`` instead of ``ValueError`` when invalid parameter combinations are passed (:issue:`36045`) - 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`) From 18b24a9fb47848791d1515ba389e32b6f910232a Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Thu, 24 Sep 2020 21:01:41 +0000 Subject: [PATCH 5/5] Update whatsnew entry --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 1b108fdf7c225..7f9b6e4181353 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -379,7 +379,7 @@ Other - Fixed metadata propagation in the :class:`Series.dt` accessor (:issue:`28283`) - Bug in :meth:`Series.transform` would give incorrect results or raise when the argument ``func`` was dictionary (:issue:`35811`) - Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`) -- Bug in :meth:`pandas.core.construction.sanitize_array` in which passing a >1d array to the :class:`Series` constructor raises a bare ``Exception``. Now raises a ``ValueError`` (:issue:`35744`) +- 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`) .. ---------------------------------------------------------------------------