Skip to content

Commit 5903f45

Browse files
authored
Merge pull request #4643 from nicoddemus/asscalar-deprecated
Use a.item() instead of deprecated np.asscalar(a)
2 parents 1bb463a + 6504746 commit 5903f45

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

changelog/4643.trivial.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use ``a.item()`` instead of the deprecated ``np.asscalar(a)`` in ``pytest.approx``.
2+
3+
``np.asscalar`` has been `deprecated <https://github.com/numpy/numpy/blob/master/doc/release/1.16.0-notes.rst#new-deprecations>`__ in ``numpy 1.16.``.

src/_pytest/python_api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def _yield_comparisons(self, actual):
150150

151151
if np.isscalar(actual):
152152
for i in np.ndindex(self.expected.shape):
153-
yield actual, np.asscalar(self.expected[i])
153+
yield actual, self.expected[i].item()
154154
else:
155155
for i in np.ndindex(self.expected.shape):
156-
yield np.asscalar(actual[i]), np.asscalar(self.expected[i])
156+
yield actual[i].item(), self.expected[i].item()
157157

158158

159159
class ApproxMapping(ApproxBase):

0 commit comments

Comments
 (0)