From: Debian Science Team Date: Wed, 26 Aug 2020 21:34:50 +0000 (+0100) Subject: Don't fail with Numpy 1.19 X-Git-Tag: archive/raspbian/1.0.5+dfsg-3+rpi1^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1073cb1fb49cf17bab6890007b961b5319ff1ab4;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 Bug-Debian: https://bugs.debian.org/963817 Forwarded: no Gbp-Pq: Name numpy119_compat.patch --- diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 0856f653..076d1257 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -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 diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 61af0209..64ec2299 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -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