From: Debian Science Team Date: Sun, 28 Jun 2020 20:47:22 +0000 (+0100) Subject: Don't fail with Numpy 1.19 X-Git-Tag: archive/raspbian/0.25.3+dfsg2-3+rpi1^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d1a80363456621e70500741b9aa96ea82883daea;p=pandas.git Don't fail with Numpy 1.19 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 Bug: https://github.com/pandas-dev/pandas/issues/32289 Forwarded: no Gbp-Pq: Name numpy119_compat.patch --- diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index c437f686..d9e2202e 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -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 diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 29e46ac7..17e3c74b 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -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