8000 Merge pull request #14620 from sethtroisi/cleanup_deprecate_index · numpy/numpy@eba0fff · GitHub
[go: up one dir, main page]

Skip to content

Commit eba0fff

Browse files
authored
Merge pull request #14620 from sethtroisi/cleanup_deprecate_index
DEP: Finish deprecation of non-integer `num` in linspace
2 parents 454c5b5 + f4dfe83 commit eba0fff

File tree

4 files changed

+10
-35
lines changed

4 files changed

+10
-35
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* np.linspace param num must be an integer. This was deprecated in NumPy 1.12.

numpy/core/function_base.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
overrides.array_function_dispatch, module='numpy')
1919

2020

21-
def _index_deprecate(i, stacklevel=2):
22-
try:
23-
i = operator.index(i)
24-
except TypeError:
25-
msg = ("object of type {} cannot be safely interpreted as "
26-
"an integer.".format(type(i)))
27-
i = int(i)
28-
stacklevel += 1
29-
warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel)
30-
return i
31-
32-
3321
def _linspace_dispatcher(start, stop, num=None, endpoint=None, retstep=None,
3422
dtype=None, axis=None):
3523
return (start, stop)
@@ -125,8 +113,13 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
125113
>>> plt.show()
126114
127115
"""
128-
# 2016-02-25, 1.12
129-
num = _index_deprecate(num)
116+
try:
117+
num = operator.index(num)
118+
except TypeError:
119+
raise TypeError(
120+
"object of type {} cannot be safely interpreted as an integer."
121+
.format(type(num)))
122+
130123
if num < 0:
131124
raise ValueError("Number of samples, %s, must be non-negative." % num)
132125
div = (num - 1) if endpoint else num

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,6 @@ def test_data_attr_assignment(self):
323323
self.assert_deprecated(a.__setattr__, args=('data', b.data))
324324

325325

326-
class TestLinspaceInvalidNumParameter(_DeprecationTestCase):
327-
"""Argument to the num parameter in linspace that cannot be
328-
safely interpreted as an integer is deprecated in 1.12.0.
329-
330-
Argument to the num parameter in linspace that cannot be
331-
safely interpreted as an integer should not be allowed.
332-
In the interest of not breaking code that passes
333-
an argument that could still be interpreted as an integer, a
334-
DeprecationWarning will be issued for the time being to give
335-
developers time to refactor relevant code.
336-
"""
337-
def test_float_arg(self):
338-
# 2016-02-25, PR#7328
339-
self.assert_deprecated(np.linspace, args=(0, 10, 2.5))
340-
341-
342326
class TestBinaryReprInsufficientWidthParameterForRepresentation(_DeprecationTestCase):
343327
"""
344328
If a 'width' parameter is passed into ``binary_repr`` that is insufficient to
@@ -594,7 +578,7 @@ class Test_GetSet_NumericOps(_DeprecationTestCase):
594578
def test_get_numeric_ops(self):
595579
from numpy.core._multiarray_tests import getset_numericops
596580
self.assert_deprecated(getset_numericops, num=2)
597-
581+
598582
# empty kwargs prevents any state actually changing which would break
599583
# other tests.
600584
self.assert_deprecated(np.set_numeric_ops, kwargs={})

numpy/core/tests/test_function_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ def test_basic(self):
236236
def test_corner(self):
237237
y = list(linspace(0, 1, 1))
238238
assert_(y == [0.0], y)
239-
with suppress_warnings() as sup:
240-
sup.filter(DeprecationWarning, ".*safely interpreted as an integer")
241-
y = list(linspace(0, 1, 2.5))
242-
assert_(y == [0.0, 1.0])
239+
assert_raises(TypeError, linspace, 0, 1, num=2.5)
243240

244241
def test_type(self):
245242
t1 = linspace(0, 1, 0).dtype

0 commit comments

Comments
 (0)
0