Fix test failures with numpy 1.19
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Sun, 28 Jun 2020 20:47:22 +0000 (21:47 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Sun, 28 Jun 2020 20:47:22 +0000 (21:47 +0100)
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 <rebecca_palmer@zoho.com>
Origin: partly upstream
Bug-Debian: https://bugs.debian.org/963817
Forwarded: not-needed

Gbp-Pq: Name numpy119_compat2.patch

pandas/_libs/src/ujson/python/objToJSON.c
pandas/tests/dtypes/test_dtypes.py
pandas/tests/frame/test_convert_to.py
pandas/tests/indexes/multi/test_analytics.py
pandas/tests/indexes/period/test_indexing.py
pandas/tests/io/test_packers.py
pandas/tests/scalar/timedelta/test_arithmetic.py
pandas/tests/scalar/timestamp/test_timestamp.py
pandas/tests/series/indexing/test_indexing.py
pandas/tests/sparse/series/test_series.py
pandas/util/testing.py

index 2890b224d29998a677d90264be55fd7f9b8d7941..160873ed778681de40140a66e1c91de987309222 100644 (file)
@@ -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) {
index d3f0d7c43ee6ba7736f3e31ba4bfe9fa19e598dc..cd661182701f9d3330f24f9f9e46d45b240585d3 100644 (file)
@@ -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_
index 2e2776a133437809c9332fcc60f501160744af2e..a3862c426fae489a8c1a7961fdcad20f6f72daf5 100644 (file)
@@ -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'),
             ),
         ],
     )
index 7c43a13c530ee8c8c9d09dda4359bfbc47ff430c..c01aa5bd7c951c4a1603a828e774e89acfc08a07 100644 (file)
@@ -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]))
 
index cf03e2c7847f0e6c24d7e2cd0ab4f960f8b66f9c..08b4f54fa220f8d68b689c6da97b75061e0b4a3e 100644 (file)
@@ -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]))
 
index 33a11087f622d0f41b5a7be1d721b759af54f58d..3a1f3e72012f021ad922a3a0c75a5508ea37dcfc 100644 (file)
@@ -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)
index 52f32d41a02ff9d78a8859353c0df431b8e0041e..1f5f741fb20290ce9b15fabeaaedf639be768874 100644 (file)
@@ -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)
 
index 401fc285424fe3332dcb8c2291e6e2634590fbe4..f2e358b6fe90cc28ac3b6a1593d372f3ef4112e1 100644 (file)
@@ -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):
index d73be76795c88d39d078dc220813488bcb995e40..d5f02fae786d5181a580ace2f3accb8ba671cb74 100644 (file)
@@ -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)):
index a9c3d157dd69b335172fe2c01e14726aedb2f962..be5699cf982f667500fac42992dd1aeeb69befec 100644 (file)
@@ -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])
 
index 93ec7522eaf28cb3287d394051954a542f506316..5785254e008ee741dacdf7f58ef5ae2b29e44a4d 100644 (file)
@@ -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__,