question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`np.diff` is broken for boolean ndarrays in 1.13.0

See original GitHub issue

Should modify the docstring accordingly, raise a meaningful error, or (preferably) make it work by hidding some logic under the hood.

Traceback:

In [11]: x = np.array([[True, True], [False, False]])

In [12]: np.diff(x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-59225436601c> in <module>()
----> 1 np.diff(x)

/usr/lib/python3.6/site-packages/numpy/lib/function_base.py in diff(a, n, axis)
   1924         return diff(a[slice1]-a[slice2], n-1, axis=axis)
   1925     else:
-> 1926         return a[slice1]-a[slice2]
   1927 
   1928 

TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

In [13]: np.__version__
Out[13]: '1.13.0'

xref https://github.com/scikit-image/scikit-image/issues/2681

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

3reactions
matthew-brettcommented, Jun 14, 2017

Well - I can see the purity argument for disallowing, but it seems to me that it is reasonable to expect diff to work on booleans, and not surprising that scikit image was doing that. So I would have thought a branch on bool was the better route.

2reactions
eric-wiesercommented, Jun 14, 2017

can’t see any deprecation warning for numpy 1.12.1 and

That’s because by default DeprecationWarning is not displayed. Add a import warnings; warnings.simplefilter('always') and you’ll see it

Read more comments on GitHub >

github_iconTop Results From Across the Web

NumPy 1.13.0 Release Notes
Object arrays that contain list objects are now printed in a way that makes clear the difference between a 2d object array, and...
Read more >
How can I convert boolean values from np.diff() to the actual ...
I am attempting to iterate through each value of the array and subtract the 2nd value from the 1st, then see if the...
Read more >
Release Notes — NumPy v1.13 Manual
In NumPy 1.13.0, results from such operations are now defined to be the same as for equivalent operations where there is no memory...
Read more >
Difficulty installing on Python 3.6 - Support
An error comes up related to test failures due to “numpy boolean subtract.” Is this error is due to using Python 3.6?
Read more >
Source code for numpy.ma.core - Astropy
Thankfully, this only makes a difference when arrays are 2- or more- ... Numpy 1.13.0, gh-8701: warn on axis default warnings.warn( "In the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found