summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-06-04 12:32:10 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2021-06-04 12:32:10 -0500
commit4353b9011d64a419c9dfa346824b82167f9ff16e (patch)
tree7bcd4bf27dc5074a2d03cc81ab36cf40a1cd1bf9 /numpy
parent6790873334b143117f4e8d1f515def8c7fdeb9fb (diff)
downloadnumpy-4353b9011d64a419c9dfa346824b82167f9ff16e.tar.gz
API: Delay string and number promotion deprecation/future warning
Unfortunately, this seems to cause some pain in pandas at least to circumvent the warning. Delaying may complicate the creation of ufuncs for strings, but otherwise should not be a big problem. We have to make sure that we can reimplement the change quickly though, it is an important change in my opinion.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/dtypemeta.c13
-rw-r--r--numpy/core/tests/test_deprecations.py35
-rw-r--r--numpy/core/tests/test_half.py6
-rw-r--r--numpy/core/tests/test_numeric.py67
-rw-r--r--numpy/core/tests/test_regression.py4
-rw-r--r--numpy/lib/tests/test_regression.py3
6 files changed, 34 insertions, 94 deletions
diff --git a/numpy/core/src/multiarray/dtypemeta.c b/numpy/core/src/multiarray/dtypemeta.c
index 40ca9ee2a..4ee721964 100644
--- a/numpy/core/src/multiarray/dtypemeta.c
+++ b/numpy/core/src/multiarray/dtypemeta.c
@@ -415,19 +415,6 @@ string_unicode_common_dtype(PyArray_DTypeMeta *cls, PyArray_DTypeMeta *other)
Py_INCREF(Py_NotImplemented);
return (PyArray_DTypeMeta *)Py_NotImplemented;
}
- if (other->type_num != NPY_STRING && other->type_num != NPY_UNICODE) {
- /* Deprecated 2020-12-19, NumPy 1.21. */
- if (DEPRECATE_FUTUREWARNING(
- "Promotion of numbers and bools to strings is deprecated. "
- "In the future, code such as `np.concatenate((['string'], [0]))` "
- "will raise an error, while `np.asarray(['string', 0])` will "
- "return an array with `dtype=object`. To avoid the warning "
- "while retaining a string result use `dtype='U'` (or 'S'). "
- "To get an array of Python objects use `dtype=object`. "
- "(Warning added in NumPy 1.21)") < 0) {
- return NULL;
- }
- }
/*
* The builtin types are ordered by complexity (aside from object) here.
* Arguably, we should not consider numbers and strings "common", but
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index ffe0147b2..42e632e4a 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -1105,41 +1105,6 @@ class TestNoseDecoratorsDeprecated(_DeprecationTestCase):
self.assert_deprecated(_test_parametrize)
-class TestStringPromotion(_DeprecationTestCase):
- # Deprecated 2020-12-19, NumPy 1.21
- warning_cls = FutureWarning
- message = "Promotion of numbers and bools to strings is deprecated."
-
- @pytest.mark.parametrize("dtype", "?bhilqpBHILQPefdgFDG")
- @pytest.mark.parametrize("string_dt", ["S", "U"])
- def test_deprecated(self, dtype, string_dt):
- self.assert_deprecated(lambda: np.promote_types(dtype, string_dt))
-
- # concatenate has to be able to promote to find the result dtype:
- arr1 = np.ones(3, dtype=dtype)
- arr2 = np.ones(3, dtype=string_dt)
- self.assert_deprecated(lambda: np.concatenate((arr1, arr2), axis=0))
- self.assert_deprecated(lambda: np.concatenate((arr1, arr2), axis=None))
-
- self.assert_deprecated(lambda: np.array([arr1[0], arr2[0]]))
-
- @pytest.mark.parametrize("dtype", "?bhilqpBHILQPefdgFDG")
- @pytest.mark.parametrize("string_dt", ["S", "U"])
- def test_not_deprecated(self, dtype, string_dt):
- # The ufunc type resolvers run into this, but giving a futurewarning
- # here is unnecessary (it ends up as an error anyway), so test that
- # no warning is given:
- arr1 = np.ones(3, dtype=dtype)
- arr2 = np.ones(3, dtype=string_dt)
-
- # Adding two arrays uses result_type normally, which would fail:
- with pytest.raises(TypeError):
- self.assert_not_deprecated(lambda: arr1 + arr2)
- # 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"
diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py
index 449a01d21..1b6fd21e1 100644
--- a/numpy/core/tests/test_half.py
+++ b/numpy/core/tests/test_half.py
@@ -71,10 +71,8 @@ class TestHalf:
def test_half_conversion_to_string(self, string_dt):
# Currently uses S/U32 (which is sufficient for float32)
expected_dt = np.dtype(f"{string_dt}32")
- with pytest.warns(FutureWarning):
- assert np.promote_types(np.float16, string_dt) == expected_dt
- with pytest.warns(FutureWarning):
- assert np.promote_types(string_dt, np.float16) == expected_dt
+ assert np.promote_types(np.float16, string_dt) == expected_dt
+ assert np.promote_types(string_dt, np.float16) == expected_dt
arr = np.ones(3, dtype=np.float16).astype(string_dt)
assert arr.dtype == expected_dt
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index aba90ece5..f5113150e 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -848,12 +848,10 @@ class TestTypes:
assert_equal(np.promote_types('<i8', '<i8'), np.dtype('i8'))
assert_equal(np.promote_types('>i8', '>i8'), np.dtype('i8'))
- with pytest.warns(FutureWarning,
- match="Promotion of numbers and bools to strings"):
- assert_equal(np.promote_types('>i8', '>U16'), np.dtype('U21'))
- assert_equal(np.promote_types('<i8', '<U16'), np.dtype('U21'))
- assert_equal(np.promote_types('>U16', '>i8'), np.dtype('U21'))
- assert_equal(np.promote_types('<U16', '<i8'), np.dtype('U21'))
+ assert_equal(np.promote_types('>i8', '>U16'), np.dtype('U21'))
+ assert_equal(np.promote_types('<i8', '<U16'), np.dtype('U21'))
+ assert_equal(np.promote_types('>U16', '>i8'), np.dtype('U21'))
+ assert_equal(np.promote_types('<U16', '<i8'), np.dtype('U21'))
assert_equal(np.promote_types('<S5', '<U8'), np.dtype('U8'))
assert_equal(np.promote_types('>S5', '>U8'), np.dtype('U8'))
@@ -901,37 +899,32 @@ class TestTypes:
S = string_dtype
- with pytest.warns(FutureWarning,
- match="Promotion of numbers and bools to strings") as record:
- # Promote numeric with unsized string:
- assert_equal(promote_types('bool', S), np.dtype(S+'5'))
- assert_equal(promote_types('b', S), np.dtype(S+'4'))
- assert_equal(promote_types('u1', S), np.dtype(S+'3'))
- assert_equal(promote_types('u2', S), np.dtype(S+'5'))
- assert_equal(promote_types('u4', S), np.dtype(S+'10'))
- assert_equal(promote_types('u8', S), np.dtype(S+'20'))
- assert_equal(promote_types('i1', S), np.dtype(S+'4'))
- assert_equal(promote_types('i2', S), np.dtype(S+'6'))
- assert_equal(promote_types('i4', S), np.dtype(S+'11'))
- assert_equal(promote_types('i8', S), np.dtype(S+'21'))
- # Promote numeric with sized string:
- assert_equal(promote_types('bool', S+'1'), np.dtype(S+'5'))
- assert_equal(promote_types('bool', S+'30'), np.dtype(S+'30'))
- assert_equal(promote_types('b', S+'1'), np.dtype(S+'4'))
- assert_equal(promote_types('b', S+'30'), np.dtype(S+'30'))
- assert_equal(promote_types('u1', S+'1'), np.dtype(S+'3'))
- assert_equal(promote_types('u1', S+'30'), np.dtype(S+'30'))
- assert_equal(promote_types('u2', S+'1'), np.dtype(S+'5'))
- assert_equal(promote_types('u2', S+'30'), np.dtype(S+'30'))
- assert_equal(promote_types('u4', S+'1'), np.dtype(S+'10'))
- assert_equal(promote_types('u4', S+'30'), np.dtype(S+'30'))
- assert_equal(promote_types('u8', S+'1'), np.dtype(S+'20'))
- assert_equal(promote_types('u8', S+'30'), np.dtype(S+'30'))
- # Promote with object:
- assert_equal(promote_types('O', S+'30'), np.dtype('O'))
-
- assert len(record) == 22 # each string promotion gave one warning
-
+ # Promote numeric with unsized string:
+ assert_equal(promote_types('bool', S), np.dtype(S+'5'))
+ assert_equal(promote_types('b', S), np.dtype(S+'4'))
+ assert_equal(promote_types('u1', S), np.dtype(S+'3'))
+ assert_equal(promote_types('u2', S), np.dtype(S+'5'))
+ assert_equal(promote_types('u4', S), np.dtype(S+'10'))
+ assert_equal(promote_types('u8', S), np.dtype(S+'20'))
+ assert_equal(promote_types('i1', S), np.dtype(S+'4'))
+ assert_equal(promote_types('i2', S), np.dtype(S+'6'))
+ assert_equal(promote_types('i4', S), np.dtype(S+'11'))
+ assert_equal(promote_types('i8', S), np.dtype(S+'21'))
+ # Promote numeric with sized string:
+ assert_equal(promote_types('bool', S+'1'), np.dtype(S+'5'))
+ assert_equal(promote_types('bool', S+'30'), np.dtype(S+'30'))
+ assert_equal(promote_types('b', S+'1'), np.dtype(S+'4'))
+ assert_equal(promote_types('b', S+'30'), np.dtype(S+'30'))
+ assert_equal(promote_types('u1', S+'1'), np.dtype(S+'3'))
+ assert_equal(promote_types('u1', S+'30'), np.dtype(S+'30'))
+ assert_equal(promote_types('u2', S+'1'), np.dtype(S+'5'))
+ assert_equal(promote_types('u2', S+'30'), np.dtype(S+'30'))
+ assert_equal(promote_types('u4', S+'1'), np.dtype(S+'10'))
+ assert_equal(promote_types('u4', S+'30'), np.dtype(S+'30'))
+ assert_equal(promote_types('u8', S+'1'), np.dtype(S+'20'))
+ assert_equal(promote_types('u8', S+'30'), np.dtype(S+'30'))
+ # Promote with object:
+ assert_equal(promote_types('O', S+'30'), np.dtype('O'))
@pytest.mark.parametrize(["dtype1", "dtype2"],
[[np.dtype("V6"), np.dtype("V10")],
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index dbfb75c9a..312d0683d 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -782,9 +782,7 @@ class TestRegression:
# Ticket #514
s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
t = []
- with pytest.warns(FutureWarning,
- match="Promotion of numbers and bools to strings"):
- np.hstack((t, s))
+ np.hstack((t, s))
def test_arr_transpose(self):
# Ticket #516
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index 94fac7ef0..373226277 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -64,8 +64,7 @@ class TestRegression:
def test_mem_string_concat(self):
# Ticket #469
x = np.array([])
- with pytest.warns(FutureWarning):
- np.append(x, 'asdasd\tasdasd')
+ np.append(x, 'asdasd\tasdasd')
def test_poly_div(self):
# Ticket #553