Don't fail with Numpy 1.19
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Wed, 26 Aug 2020 21:34:50 +0000 (22:34 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Wed, 26 Aug 2020 21:34:50 +0000 (22:34 +0100)
Creating a nested DataFrame (which was already not recommended)
via the constructor no longer works.
Give a clearer error and xfail the tests.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Bug: https://github.com/pandas-dev/pandas/issues/32289
Bug-Debian: https://bugs.debian.org/963817
Forwarded: no

Gbp-Pq: Name numpy119_compat.patch

pandas/core/internals/construction.py
pandas/tests/frame/test_constructors.py

index 0856f65306849d4c99680d99dde254abb85ce234..076d12574ebc4b437830b5d67c462b241d517c57 100644 (file)
@@ -292,7 +292,7 @@ def prep_ndarray(values, copy=True) -> np.ndarray:
     if values.ndim == 1:
         values = values.reshape((values.shape[0], 1))
     elif values.ndim != 2:
-        raise ValueError("Must pass 2-d input")
+        raise ValueError("Plain DataFrames must be 2-d - for higher dimensions use MultiIndex or the python3-xarray package.  If you are trying to create a nested DataFrame (which is not recommended) see https://github.com/pandas-dev/pandas/issues/32289")
 
     return values
 
index 61af02090f7db71ad3135db0be8c98d123cc8146..64ec229976e8db7ed84c18a1c7c81bbe717a4994 100644 (file)
@@ -145,7 +145,7 @@ class TestDataFrameConstructors:
         assert df.loc[1, 0] is None
         assert df.loc[0, 1] == "2"
 
-    @pytest.mark.xfail(_is_numpy_dev, reason="Interprets list of frame as 3D")
+    @pytest.mark.xfail(condition=True,strict=False,raises=ValueError, reason="Interprets list of frame as 3D, https://github.com/pandas-dev/pandas/issues/32289")
     def test_constructor_list_frames(self):
         # see gh-3243
         result = DataFrame([DataFrame()])
@@ -477,7 +477,7 @@ class TestDataFrameConstructors:
             DataFrame(index=[0], columns=range(0, 4), data=arr)
 
         # higher dim raise exception
-        with pytest.raises(ValueError, match="Must pass 2-d input"):
+        with pytest.raises(ValueError, match="Plain DataFrames must be 2-d"):
             DataFrame(np.zeros((3, 3, 3)), columns=["A", "B", "C"], index=[1])
 
         # wrong size axis labels
@@ -498,7 +498,7 @@ class TestDataFrameConstructors:
         with pytest.raises(ValueError, match=msg):
             DataFrame({"a": False, "b": True})
 
-    @pytest.mark.xfail(_is_numpy_dev, reason="Interprets embedded frame as 3D")
+    @pytest.mark.xfail(condition=True,strict=False,raises=ValueError, reason="Interprets embedded frame as 3D, https://github.com/pandas-dev/pandas/issues/32289")
     def test_constructor_with_embedded_frames(self):
 
         # embedded data frames
@@ -764,7 +764,7 @@ class TestDataFrameConstructors:
             DataFrame(mat, columns=["A", "B"], index=[1, 2])
 
         # higher dim raise exception
-        with pytest.raises(ValueError, match="Must pass 2-d input"):
+        with pytest.raises(ValueError, match="Plain DataFrames must be 2-d"):
             DataFrame(empty((3, 3, 3)), columns=["A", "B", "C"], index=[1])
 
         # automatic labeling