summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_deprecations.py34
-rw-r--r--numpy/core/tests/test_ufunc.py51
2 files changed, 81 insertions, 4 deletions
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 4d840ec1a..ec4112e69 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -1141,3 +1141,37 @@ class TestStringPromotion(_DeprecationTestCase):
# np.equal uses a different type resolver:
with pytest.raises(TypeError):
self.assert_not_deprecated(lambda: np.equal(arr1, arr2))
+
+
+class TestSingleElementSignature(_DeprecationTestCase):
+ # Deprecated 2021-04-01, NumPy 1.21
+ message = r"The use of a length 1"
+
+ def test_deprecated(self):
+ self.assert_deprecated(lambda: np.add(1, 2, signature="d"))
+ self.assert_deprecated(lambda: np.add(1, 2, sig=(np.dtype("l"),)))
+
+
+class TestComparisonBadDType(_DeprecationTestCase):
+ # Deprecated 2021-04-01, NumPy 1.21
+ message = r"using `dtype=` in comparisons is only useful for"
+
+ def test_deprecated(self):
+ self.assert_deprecated(lambda: np.equal(1, 1, dtype=np.int64))
+ # Not an error only for the transition
+ self.assert_deprecated(lambda: np.equal(1, 1, sig=(None, None, "l")))
+
+ def test_not_deprecated(self):
+ np.equal(True, False, dtype=bool)
+ np.equal(3, 5, dtype=bool, casting="unsafe")
+ np.equal([None], [4], dtype=object)
+
+class TestComparisonBadObjectDType(_DeprecationTestCase):
+ # Deprecated 2021-04-01, NumPy 1.21 (different branch of the above one)
+ message = r"using `dtype=object` \(or equivalent signature\) will"
+ warning_cls = FutureWarning
+
+ def test_deprecated(self):
+ self.assert_deprecated(lambda: np.equal(1, 1, dtype=object))
+ self.assert_deprecated(
+ lambda: np.equal(1, 1, sig=(None, None, object)))
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 96bfe7c33..7b71a4a65 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -410,9 +410,12 @@ class TestUfunc:
def test_forced_sig(self):
a = 0.5*np.arange(3, dtype='f8')
assert_equal(np.add(a, 0.5), [0.5, 1, 1.5])
- assert_equal(np.add(a, 0.5, sig='i', casting='unsafe'), [0, 0, 1])
+ with pytest.warns(DeprecationWarning):
+ assert_equal(np.add(a, 0.5, sig='i', casting='unsafe'), [0, 0, 1])
assert_equal(np.add(a, 0.5, sig='ii->i', casting='unsafe'), [0, 0, 1])
- assert_equal(np.add(a, 0.5, sig=('i4',), casting='unsafe'), [0, 0, 1])
+ with pytest.warns(DeprecationWarning):
+ assert_equal(np.add(a, 0.5, sig=('i4',), casting='unsafe'),
+ [0, 0, 1])
assert_equal(np.add(a, 0.5, sig=('i4', 'i4', 'i4'),
casting='unsafe'), [0, 0, 1])
@@ -420,18 +423,58 @@ class TestUfunc:
np.add(a, 0.5, out=b)
assert_equal(b, [0.5, 1, 1.5])
b[:] = 0
- np.add(a, 0.5, sig='i', out=b, casting='unsafe')
+ with pytest.warns(DeprecationWarning):
+ np.add(a, 0.5, sig='i', out=b, casting='unsafe')
assert_equal(b, [0, 0, 1])
b[:] = 0
np.add(a, 0.5, sig='ii->i', out=b, casting='unsafe')
assert_equal(b, [0, 0, 1])
b[:] = 0
- np.add(a, 0.5, sig=('i4',), out=b, casting='unsafe')
+ with pytest.warns(DeprecationWarning):
+ np.add(a, 0.5, sig=('i4',), out=b, casting='unsafe')
assert_equal(b, [0, 0, 1])
b[:] = 0
np.add(a, 0.5, sig=('i4', 'i4', 'i4'), out=b, casting='unsafe')
assert_equal(b, [0, 0, 1])
+ def test_forced_dtype_times(self):
+ # Signatures only set the type numbers (not the actual loop dtypes)
+ # so using `M` in a signature/dtype should generally work:
+ a = np.array(['2010-01-02', '1999-03-14', '1833-03'], dtype='>M8[D]')
+ np.maximum(a, a, dtype="M")
+ np.maximum.reduce(a, dtype="M")
+
+ arr = np.arange(10, dtype="m8[s]")
+ np.add(arr, arr, dtype="m")
+ np.maximum(arr, arr, dtype="m")
+
+ def test_forced_dtype_warning(self):
+ # does not warn (test relies on bad pickling behaviour, simply remove
+ # it if the `assert int64 is not int64_2` should start failing.
+ int64 = np.dtype("int64")
+ int64_2 = pickle.loads(pickle.dumps(int64))
+ assert int64 is not int64_2
+ np.add(3, 4, dtype=int64_2)
+
+ arr = np.arange(10, dtype="m8[s]")
+ with pytest.warns(UserWarning,
+ match="The `dtype` and `signature` arguments to") as rec:
+ np.add(3, 5, dtype=int64.newbyteorder())
+ np.add(3, 5, dtype="m8[ns]") # previously used the "ns"
+ np.add(arr, arr, dtype="m8[ns]") # never preserved the "ns"
+ np.maximum(arr, arr, dtype="m8[ns]") # previously used the "ns"
+ np.maximum.reduce(arr, dtype="m8[ns]") # never preserved the "ns"
+
+ assert len(rec) == 5 # each of the above call should cause one
+
+ # Also check the error paths:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
+ with pytest.raises(UserWarning):
+ np.add(3, 5, dtype="m8[ns]")
+ with pytest.raises(UserWarning):
+ np.maximum.reduce(arr, dtype="m8[ns]")
+
def test_true_divide(self):
a = np.array(10)
b = np.array(20)