From: Debian Science Team Date: Sun, 28 Jun 2020 20:47:22 +0000 (+0100) Subject: Fix test failures with numpy 1.19 X-Git-Tag: archive/raspbian/0.25.3+dfsg2-3+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2abb8d873176f04908d4b632186f5807e8e3493c;p=pandas.git Fix test failures with numpy 1.19 Remove use of no-longer-existing constant (and replace by its value on Python 3) Don't pass dtype to np.datetime64 Ignore deprecations and error message rewordings Author: jbrockmendel, Ali McMaster, Rebecca N. Palmer Origin: partly upstream Bug-Debian: https://bugs.debian.org/963817 Forwarded: not-needed Gbp-Pq: Name numpy119_compat2.patch --- diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 2890b224..160873ed 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -176,9 +176,9 @@ void *initObjToJSON(void) Py_DECREF(mod_nattype); } - /* Initialise numpy API and use 2/3 compatible return */ + /* Initialise numpy API */ import_array(); - return NUMPY_IMPORT_ARRAY_RETVAL; + return NULL; } static TypeContext *createTypeContext(void) { diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index d3f0d7c4..cd661182 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -46,7 +46,7 @@ class Base: assert not is_dtype_equal(self.dtype, np.int64) def test_numpy_informed(self): - with pytest.raises(TypeError, match="data type not understood"): + with pytest.raises(TypeError, match="data type not understood|Cannot interpret .* as a data type"): np.dtype(self.dtype) assert not self.dtype == np.str_ diff --git a/pandas/tests/frame/test_convert_to.py b/pandas/tests/frame/test_convert_to.py index 2e2776a1..a3862c42 100644 --- a/pandas/tests/frame/test_convert_to.py +++ b/pandas/tests/frame/test_convert_to.py @@ -320,7 +320,7 @@ class TestDataFrameConvertTo(TestData): # Check that bad types raise ( dict(index=False, column_dtypes={"A": "int32", "B": "foo"}), - (TypeError, 'data type "foo" not understood'), + (TypeError, 'data type .foo. not understood'), ), ], ) diff --git a/pandas/tests/indexes/multi/test_analytics.py b/pandas/tests/indexes/multi/test_analytics.py index 7c43a13c..c01aa5bd 100644 --- a/pandas/tests/indexes/multi/test_analytics.py +++ b/pandas/tests/indexes/multi/test_analytics.py @@ -218,7 +218,7 @@ def test_take_fill_value(): with pytest.raises(ValueError, match=msg): idx.take(np.array([1, 0, -5]), fill_value=True) - msg = "index -5 is out of bounds for size 4" + msg = "index -5 is out of bounds for.* size 4" with pytest.raises(IndexError, match=msg): idx.take(np.array([1, -5])) diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index cf03e2c7..08b4f54f 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -342,7 +342,7 @@ class TestTake: with pytest.raises(ValueError, match=msg): idx.take(np.array([1, 0, -5]), fill_value=True) - msg = "index -5 is out of bounds for size 3" + msg = "index -5 is out of bounds for.* size 3" with pytest.raises(IndexError, match=msg): idx.take(np.array([1, -5])) diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index 33a11087..3a1f3e72 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -714,6 +714,7 @@ class TestCompression(TestPackers): with catch_warnings(): filterwarnings("ignore", category=FutureWarning) + filterwarnings("ignore", category=DeprecationWarning) i_rec = self.encode_decode(self.frame, compress=compress) for k in self.frame.keys(): @@ -755,6 +756,7 @@ class TestCompression(TestPackers): with tm.assert_produces_warning(None): with catch_warnings(): filterwarnings("ignore", category=FutureWarning) + filterwarnings("ignore", category=DeprecationWarning) empty_unpacked = self.encode_decode(empty, compress=compress) tm.assert_numpy_array_equal(empty_unpacked, empty) @@ -764,6 +766,7 @@ class TestCompression(TestPackers): with tm.assert_produces_warning(None): with catch_warnings(): filterwarnings("ignore", category=FutureWarning) + filterwarnings("ignore", category=DeprecationWarning) char_unpacked = self.encode_decode(char, compress=compress) tm.assert_numpy_array_equal(char_unpacked, char) diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 52f32d41..1f5f741f 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -447,7 +447,7 @@ class TestTimedeltaMultiplicationDivision: # GH#18846 td = Timedelta(hours=3, minutes=3) - dt64 = np.datetime64("2016-01-01", dtype="datetime64[us]") + dt64 = np.datetime64("2016-01-01", "us") with pytest.raises(TypeError): td.__rfloordiv__(dt64) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 401fc285..f2e358b6 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -576,7 +576,7 @@ class TestTimestampConstructors: for date_string in out_of_bounds_dates: for unit in time_units: - dt64 = np.datetime64(date_string, dtype="M8[{unit}]".format(unit=unit)) + dt64 = np.datetime64(date_string, unit) with pytest.raises(ValueError): Timestamp(dt64) @@ -584,7 +584,7 @@ class TestTimestampConstructors: for date_string in in_bounds_dates: for unit in time_units: - dt64 = np.datetime64(date_string, dtype="M8[{unit}]".format(unit=unit)) + dt64 = np.datetime64(date_string, unit) Timestamp(dt64) def test_min_valid(self): diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index d73be767..d5f02fae 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -855,7 +855,7 @@ def test_take(): expected = Series([4, 2, 4], index=[4, 3, 4]) tm.assert_series_equal(actual, expected) - msg = "index {} is out of bounds for size 5" + msg = "index {} is out of bounds for.* size 5" with pytest.raises(IndexError, match=msg.format(10)): s.take([1, 10]) with pytest.raises(IndexError, match=msg.format(5)): diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index a9c3d157..be5699cf 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -520,7 +520,7 @@ class TestSparseSeries(SharedWithSparse): self._check_all(_compare_with_dense) - msg = "index 21 is out of bounds for size 20" + msg = "index 21 is out of bounds for.* size 20" with pytest.raises(IndexError, match=msg): self.bseries.take([0, len(self.bseries) + 1]) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 93ec7522..5785254e 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -2704,6 +2704,8 @@ def assert_produces_warning( continue if actual_warning.category==DeprecationWarning and ('jedi' in actual_warning.filename or 'IPython' in actual_warning.filename): continue + if actual_warning.category==np.VisibleDeprecationWarning and "Creating an ndarray from ragged nested sequences" in str(actual_warning.message): + continue extra_warnings.append( ( actual_warning.category.__name__,