diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/numerictypes.py | 19 | ||||
-rw-r--r-- | numpy/core/tests/test_numerictypes.py | 15 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 4 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 2 |
4 files changed, 33 insertions, 7 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 3d1cb6fd1..8b210a1a1 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -80,6 +80,7 @@ Exported symbols include: """ import numbers +import warnings from numpy.core.multiarray import ( ndarray, array, dtype, datetime_data, datetime_as_string, @@ -599,6 +600,16 @@ def find_common_type(array_types, scalar_types): """ Determine common type following standard coercion rules. + .. deprecated:: NumPy 1.24 + + This function is deprecated, use `numpy.promote_types` or + `numpy.result_type` instead. To achieve semantics for the + `scalar_types` argument, use `numpy.result_type` and pass the Python + values `0`, `0.0`, or `0j`. + This will give the same results in almost all cases. + More information and rare exception can be found in the + `NumPy 1.24 release notes <https://numpy.org/devdocs/release/1.24.0-notes.html>`_. + Parameters ---------- array_types : sequence @@ -646,6 +657,14 @@ def find_common_type(array_types, scalar_types): dtype('complex128') """ + # Deprecated 2022-11-07, NumPy 1.24 + warnings.warn( + "np.find_common_type is deprecated. Please use `np.result_type` " + "or `np.promote_types`.\n" + "See https://numpy.org/devdocs/release/1.24.0-notes.html and the " + "docs for more information. (Deprecated NumPy 1.24)", + DeprecationWarning, stacklevel=2) + array_types = [dtype(x) for x in array_types] scalar_types = [dtype(x) for x in scalar_types] diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index ffe8716e7..6aedbf569 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -339,23 +339,28 @@ class TestEmptyField: class TestCommonType: def test_scalar_loses1(self): - res = np.find_common_type(['f4', 'f4', 'i2'], ['f8']) + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type(['f4', 'f4', 'i2'], ['f8']) assert_(res == 'f4') def test_scalar_loses2(self): - res = np.find_common_type(['f4', 'f4'], ['i8']) + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type(['f4', 'f4'], ['i8']) assert_(res == 'f4') def test_scalar_wins(self): - res = np.find_common_type(['f4', 'f4', 'i2'], ['c8']) + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type(['f4', 'f4', 'i2'], ['c8']) assert_(res == 'c8') def test_scalar_wins2(self): - res = np.find_common_type(['u4', 'i4', 'i4'], ['f4']) + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type(['u4', 'i4', 'i4'], ['f4']) assert_(res == 'f8') def test_scalar_wins3(self): # doesn't go up to 'f16' on purpose - res = np.find_common_type(['u8', 'i8', 'i8'], ['f8']) + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type(['u8', 'i8', 'i8'], ['f8']) assert_(res == 'f8') class TestMultipleFields: diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 427e868e8..c3b9dab69 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1673,7 +1673,9 @@ class TestRegression: def test_find_common_type_boolean(self): # Ticket #1695 - assert_(np.find_common_type([], ['?', '?']) == '?') + with pytest.warns(DeprecationWarning, match="np.find_common_type"): + res = np.find_common_type([], ['?', '?']) + assert res == '?' def test_empty_mul(self): a = np.array([1.]) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index f32038a01..6196dcfab 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -4461,7 +4461,7 @@ class TestMaskedArrayFunctions: x = np.arange(4, dtype=np.int32) y = np.arange(4, dtype=np.float32) * 2.2 test = where(x > 1.5, y, x).dtype - control = np.find_common_type([np.int32, np.float32], []) + control = np.result_type(np.int32, np.float32) assert_equal(test, control) def test_where_broadcast(self): |