diff options
author | Guilherme Leobas <guilhermeleobas@gmail.com> | 2019-08-08 08:31:42 -0300 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2019-08-08 14:31:42 +0300 |
commit | 68626acba30ab59fa1ef27c25eb7ed93f227396e (patch) | |
tree | 8f0cb6135ef50abd76da3213d257f291425bcd5e /numpy/core | |
parent | 5096930221477593b8e71f688e3c71ef10d7ee18 (diff) | |
download | numpy-68626acba30ab59fa1ef27c25eb7ed93f227396e.tar.gz |
DEP: Deprecate np.alen (#14181)
* Deprecate and fix tests for alen
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/fromnumeric.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 20 |
3 files changed, 21 insertions, 9 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 75a6bae7f..c9ea44425 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -2782,6 +2782,10 @@ def alen(a): 7 """ + # NumPy 1.18.0, 2019-08-02 + warnings.warn( + "`np.alen` is deprecated, use `len` instead", + DeprecationWarning, stacklevel=2) try: return len(a) except TypeError: diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index d6c870a94..e8aa0c70b 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -489,6 +489,12 @@ class TestBincount(_DeprecationTestCase): self.assert_deprecated(lambda: np.bincount([1, 2, 3], minlength=None)) +class TestAlen(_DeprecationTestCase): + # 2019-08-02, 1.18.0 + def test_alen(self): + self.assert_deprecated(lambda: np.alen(np.array([1, 2, 3]))) + + class TestGeneratorSum(_DeprecationTestCase): # 2018-02-25, 1.15.0 def test_generator_sum(self): diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index bfc25e9ee..6a115f41b 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -6405,20 +6405,22 @@ class TestInner(object): class TestAlen(object): def test_basic(self): - m = np.array([1, 2, 3]) - assert_equal(np.alen(m), 3) + with pytest.warns(DeprecationWarning): + m = np.array([1, 2, 3]) + assert_equal(np.alen(m), 3) - m = np.array([[1, 2, 3], [4, 5, 7]]) - assert_equal(np.alen(m), 2) + m = np.array([[1, 2, 3], [4, 5, 7]]) + assert_equal(np.alen(m), 2) - m = [1, 2, 3] - assert_equal(np.alen(m), 3) + m = [1, 2, 3] + assert_equal(np.alen(m), 3) - m = [[1, 2, 3], [4, 5, 7]] - assert_equal(np.alen(m), 2) + m = [[1, 2, 3], [4, 5, 7]] + assert_equal(np.alen(m), 2) def test_singleton(self): - assert_equal(np.alen(5), 1) + with pytest.warns(DeprecationWarning): + assert_equal(np.alen(5), 1) class TestChoose(object): |