Don't fail with Numpy 1.19
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Sun, 16 Aug 2020 19:09:14 +0000 (20:09 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Sun, 16 Aug 2020 19:09:14 +0000 (20:09 +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
Forwarded: no

Gbp-Pq: Name numpy119_compat.patch

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

index c437f686bd17ba749c18fbda99b1ad7d0db93a88..d9e2202e11de9bb6b6d1698cba239ed6b0a7aa96 100644 (file)
@@ -292,7 +292,7 @@ def prep_ndarray(values, copy=True):
     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 29e46ac70c9433ad111e507a987a0e9e01f43d06..17e3c74beeb804661b5c74228dc560912add4624 100644 (file)
@@ -130,6 +130,7 @@ class TestDataFrameConstructors:
         assert df.loc[1, 0] is None
         assert df.loc[0, 1] == "2"
 
+    @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()])
@@ -457,7 +458,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
@@ -478,6 +479,7 @@ class TestDataFrameConstructors:
         with pytest.raises(ValueError, match=msg):
             DataFrame({"a": False, "b": True})
 
+    @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
@@ -745,7 +747,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