internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: numpy/numpy

Issue:
__array_prepare__ produces bad shape for np.ma.masked
A somewhat contrived example

```python
>>> source = np.ma.masked  # comes from user function, could be anything
>>> source = np.asanyarray(source)  # force to array, so we can try to copy the type
>>> outarr = np.zeros((2, 2))  # allocate a raw ndarray for the result
>>> bad = source.__array_prepare__(outarr) # prepare that raw array for operations 
>>> bad.shape
(2, 2)
>>> bad.data.shape
()  # uh oh
>>> bad.mask.shape
()  # spaghettios
```

Which leads to failures like
```python
>>> res.transpose((1, 0))
Traceback (most recent call last):
  File "<pyshell#78>", line 1, in <module>
    np.asanyarray(np.ma.masked).__array_prepare__(np.zeros((2, 2))).transpose((1, 0))
  File "C:\Program Files\Python 3.5\lib\site-packages\numpy\ma\core.py", line 2509, in wrapped_method
    result = getattr(self._data, funcname)(*args, **params)
ValueError: axes don't match array
```

This come up when trying to invoke #8441 on masked arrays.

Is this a bug, or an invalid use of `__array_prepare__`?


Discussion:
Related:

```python
def assert_broadcasts(ufunc, a, b):
    expected = np.broadcast(a, b).shape
    actual = ufunc(a, b).shape
    assert expected == actual

assert_broadcasts(np.add, [1, 2, 3], 1)
assert_broadcasts(np.add, [1, 2, 3], np.ma.masked)  # AssertionError
```

Resolving patch:
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -6130,8 +6130,11 @@ def __new__(self):
     def __array_finalize__(self, obj):
         return
 
-    def __array_wrap__(self, obj):
-        return self
+    def __array_prepare__(self, obj, context=None):
+        return self.view(MaskedArray).__array_prepare__(obj, context)
+
+    def __array_wrap__(self, obj, context=None):
+        return self.view(MaskedArray).__array_wrap__(obj, context)
 
     def __str__(self):
         return str(masked_print_option._display)


Test patch:
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4425,6 +4425,28 @@ def test_count(self):
         assert_raises(ValueError, count, np.ma.array(1), axis=1)
 
 
+class TestMaskedConstant(TestCase):
+    def _do_add_test(self, add):
+        # sanity check
+        self.assertIs(add(np.ma.masked, 1), np.ma.masked)
+
+        # now try with a vector
+        vector = np.array([1, 2, 3])
+        result = add(np.ma.masked, vector)
+
+        # lots of things could go wrong here
+        assert_(result is not np.ma.masked)
+        assert_(not isinstance(result, np.ma.core.MaskedConstant))
+        assert_equal(result.shape, vector.shape)
+        assert_equal(np.ma.getmask(result), np.ones(vector.shape, dtype=bool))
+
+    def test_ufunc(self):
+        self._do_add_test(np.add)
+
+    def test_operator(self):
+        self._do_add_test(lambda a, b: a + b)
+
+
 def test_masked_array():
     a = np.ma.array([0, 1, 2, 3], mask=[0, 0, 1, 0])
     assert_equal(np.argwhere(a), [[1], [3]])
Repository: numpy/numpy

Issue:
BUG: MaskedArray inappropriate "setting an array element with a sequence"
A worse version of #8461

Obvious bug with scalar arrays:
```python
>>> mask_0d = np.ma.masked_array(1, mask=True)
>>> arr = np.ma.arange(5)
>>> arr[0] = mask_0d
ValueError: setting an array element with a sequence.
```
More of a missing feature of list conversion:
```python
>>> arr = np.ma.arange(5)
>>> arr[1:3] = [1, np.ma.masked]
ValueError: setting an array element with a sequence.

#expected result:
>>> arr
masked_array(data = [0 1 -- 3 4],
             mask = [False False  True False False],
       fill_value = 999999)
```

BUG: MaskedArray inappropriate "setting an array element with a sequence"
A worse version of #8461

Obvious bug with scalar arrays:
```python
>>> mask_0d = np.ma.masked_array(1, mask=True)
>>> arr = np.ma.arange(5)
>>> arr[0] = mask_0d
ValueError: setting an array element with a sequence.
```
More of a missing feature of list conversion:
```python
>>> arr = np.ma.arange(5)
>>> arr[1:3] = [1, np.ma.masked]
ValueError: setting an array element with a sequence.

#expected result:
>>> arr
masked_array(data = [0 1 -- 3 4],
             mask = [False False  True False False],
       fill_value = 999999)
```



Discussion:

Resolving patch:
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3264,7 +3264,7 @@ def __setitem__(self, indx, value):
             return
 
         # Get the _data part of the new value
-        dval = value
+        dval = getattr(value, '_data', value)
         # Get the _mask part of the new value
         mval = getattr(value, '_mask', nomask)
         if nbfields and mval is nomask:


Test patch:
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4256,6 +4256,13 @@ def test_setitem(self):
         a[0]['a'] = 2
         assert_equal(a.mask, control)
 
+    def test_setitem_scalar(self):
+        # 8510
+        mask_0d = np.ma.masked_array(1, mask=True)
+        arr = np.ma.arange(3)
+        arr[0] = mask_0d
+        assert_array_equal(arr.mask, [True, False, False])
+
     def test_element_len(self):
         # check that len() works for mvoid (Github issue #576)
         for rec in self.data['base']:
Repository: numpy/numpy

Issue:
`iscomplexobj` not working for custom dtypes
Hi,

As wished by @shoyer in PR #7936 here a new Issue. The PR introduced a small backwards incompatibility, that now bites the [tinyarray](https://gitlab.kwant-project.org/kwant/tinyarray) project, which provides a mostly Numpy compatible array on top of `PyVarObject`s. As a dtype tinyarrays simply return a Python type like `complex`, which is not recognized by `iscomplexobj` anymore.

The problem can be examplified by imagining a custom array type on top of list
```
class MyArray(list):
    @property
    def dtype(self):
        return type(self[0])
```
We can use this like this
```
>>> import numpy as np
>>> a = MyArray([1+0j, 2+0j, 3+0j])
>>> np.lib.type_check.iscomplexobj(a)
False
>>> np.asarray(a)
array([ 1.+0.j,  2.+0.j,  3.+0.j])
>>> issubclass(np.asarray(a).dtype.type, np.complexfloating)
True
```
where the last line is equal to the former implementation of `iscomplex`.



Discussion:
The issue could be fixed by adding a call to `getattr` in `iscomplexobj`:
```
def iscomplexobj(x):
    try:
        dtype = x.dtype
        getattr(dtype, "type")            
    except AttributeError:
        dtype = np.asarray(x).dtype
    try:
        return issubclass(dtype.type, np.complexfloating)
    except AttributeError:
        return False
```
This should reproduce the previous behaviour of `iscomplexobj`.
@behrmann why don't you open up a PR?

Resolving patch:
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -268,12 +268,10 @@ def iscomplexobj(x):
     """
     try:
         dtype = x.dtype
+        type_ = dtype.type
     except AttributeError:
-        dtype = asarray(x).dtype
-    try:
-        return issubclass(dtype.type, _nx.complexfloating)
-    except AttributeError:
-        return False
+        type_ = asarray(x).dtype.type
+    return issubclass(type_, _nx.complexfloating)
 
 
 def isrealobj(x):


Test patch:
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -183,6 +183,15 @@ def dtype(self):
         dummy = DummyPd()
         assert_(iscomplexobj(dummy))
 
+    def test_custom_dtype_duck(self):
+        class MyArray(list):
+            @property
+            def dtype(self):
+                return complex
+
+        a = MyArray([1+0j, 2+0j, 3+0j])
+        assert_(iscomplexobj(a))
+
 
 class TestIsrealobj(TestCase):
     def test_basic(self):
Repository: numpy/numpy

Issue:
IndexError on apply_along_axis with empty 2D array
```
In [21]: a = np.empty(shape=(0,0))

In [22]: np.lib.apply_along_axis(sum, 1, a)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-2fcce4e707fd> in <module>()
----> 1 np.lib.apply_along_axis(sum, 1, a)

myvirtualenv/lib/python2.7/site-packages/numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/lib/shape_base.pyc in apply_along_axis(func1d, axis, arr, *args, **kwargs)
     89     outshape = asarray(arr.shape).take(indlist)
     90     i.put(indlist, ind)
---> 91     res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
     92     #  if res is a number, then we have a smaller output array
     93     if isscalar(res):

IndexError: index 0 is out of bounds for axis 0 with size 0
```



Discussion:

Resolving patch:
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -109,7 +109,10 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
     inds = ndindex(inarr_view.shape[:-1])
 
     # invoke the function on the first item
-    ind0 = next(inds)
+    try:
+        ind0 = next(inds)
+    except StopIteration:
+        raise ValueError('Cannot apply_along_axis when any iteration dimensions are 0')
     res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs))
 
     # build a buffer for storing evaluations of func1d.


Test patch:
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -140,6 +140,25 @@ def sample_1d(x):
         res = np.apply_along_axis(sample_1d, 1, np.array([[1, 2], [3, 4]]))
         assert_array_equal(res, np.array([[2, 1], [4, 3]]))
 
+    def test_empty(self):
+        # can't apply_along_axis when there's no chance to call the function
+        def never_call(x):
+            assert_(False) # should never be reached
+
+        a = np.empty((0, 0))
+        assert_raises(ValueError, np.apply_along_axis, never_call, 0, a)
+        assert_raises(ValueError, np.apply_along_axis, never_call, 1, a)
+
+        # but it's sometimes ok with some non-zero dimensions
+        def empty_to_1(x):
+            assert_(len(x) == 0)
+            return 1
+
+        a = np.empty((10, 0))
+        actual = np.apply_along_axis(empty_to_1, 1, a)
+        assert_equal(actual, np.ones(10))
+        assert_raises(ValueError, np.apply_along_axis, empty_to_1, 0, a)
+
 
 class TestApplyOverAxes(TestCase):
     def test_simple(self):
Repository: numpy/numpy

Issue:
BUG: np.apply_along_axis produces nested object scalars
"Regression" from #8441:

```python
>>> np.apply_along_axis(lambda x: set(x), 1, [[1, 2, 3]])
array([array({1, 2, 3}, dtype=object)], dtype=object)
```

Expected

```python
array([{1, 2, 3}], dtype=object)
```

Before the #8441 patch (#5248):
```python
array([[{1, 2, 3}, {1, 2, 3}, {1, 2, 3}]], dtype=object)
```

This comes down to the fact that `arr[...] = np.array(a_scalar)` does a different thing when the scalar is of `object` dtype



Discussion:

Resolving patch:
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -105,8 +105,10 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
     in_dims = list(range(nd))
     inarr_view = transpose(arr, in_dims[:axis] + in_dims[axis+1:] + [axis])
 
-    # compute indices for the iteration axes
+    # compute indices for the iteration axes, and append a trailing ellipsis to
+    # prevent 0d arrays decaying to scalars, which fixes gh-8642
     inds = ndindex(inarr_view.shape[:-1])
+    inds = (ind + (Ellipsis,) for ind in inds)
 
     # invoke the function on the first item
     try:


Test patch:
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -159,6 +159,21 @@ def empty_to_1(x):
         assert_equal(actual, np.ones(10))
         assert_raises(ValueError, np.apply_along_axis, empty_to_1, 0, a)
 
+    def test_with_iterable_object(self):
+        # from issue 5248
+        d = np.array([
+            [set([1, 11]), set([2, 22]), set([3, 33])],
+            [set([4, 44]), set([5, 55]), set([6, 66])]
+        ])
+        actual = np.apply_along_axis(lambda a: set.union(*a), 0, d)
+        expected = np.array([{1, 11, 4, 44}, {2, 22, 5, 55}, {3, 33, 6, 66}])
+
+        assert_equal(actual, expected)
+
+        # issue 8642 - assert_equal doesn't detect this!
+        for i in np.ndindex(actual.shape):
+            assert_equal(type(actual[i]), type(expected[i]))
+
 
 class TestApplyOverAxes(TestCase):
     def test_simple(self):
Repository: numpy/numpy

Issue:
Option for an in-place nan_to_num conversion
Currently the `nan_to_num` function always makes a copy of the input array due to a cast to `np.array` at the beginning of the function call. It would be nice to allow for an in-place operation if possible (by just passing through a copy argument).

I'd be happy to make a PR unless there is an underlying problem with the operation being in-place.


Discussion:
Seems pretty reasonable, and sounds like an easy PR

Resolving patch:
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -315,7 +315,7 @@ def _getmaxmin(t):
     f = getlimits.finfo(t)
     return f.max, f.min
 
-def nan_to_num(x):
+def nan_to_num(x, copy=True):
     """
     Replace nan with zero and inf with finite numbers.
 
@@ -327,6 +327,13 @@ def nan_to_num(x):
     ----------
     x : array_like
         Input data.
+    copy : bool, optional
+        Whether to create a copy of `x` (True) or to replace values
+        in-place (False). The in-place operation only occurs if
+        casting to an array does not require a copy.
+        Default is True.
+
+        .. versionadded:: 1.13
 
     Returns
     -------
@@ -361,7 +368,7 @@ def nan_to_num(x):
             -1.28000000e+002,   1.28000000e+002])
 
     """
-    x = _nx.array(x, subok=True)
+    x = _nx.array(x, subok=True, copy=copy)
     xtype = x.dtype.type
     if not issubclass(xtype, _nx.inexact):
         return x


Test patch:
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -320,6 +320,16 @@ def test_generic(self):
         assert_(vals[1] == 0)
         assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
 
+        # perform the same test but in-place
+        with np.errstate(divide='ignore', invalid='ignore'):
+            vals = np.array((-1., 0, 1))/0.
+        result = nan_to_num(vals, copy=False)
+
+        assert_(result is vals)
+        assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
+        assert_(vals[1] == 0)
+        assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
+
     def test_integer(self):
         vals = nan_to_num(1)
         assert_all(vals == 1)
Repository: numpy/numpy

Issue:
Broken link in Documentation
I wanted to report a broken link I found in the NumPy User Guide. 

In [NumPy Basics / Subclassing ndarray](https://docs.scipy.org/doc/numpy/user/basics.subclassing.html), credit is given to Pierre Gerard-Marchant and his contribution to a linked wiki page at [http://www.scipy.org/Subclasses](http://www.scipy.org/Subclasses), but this is currently redirecting to a 404.

In #8520, @charris notes that the wiki is extinct, so perhaps the link to the wiki should be deleted. Any ideas on whether this link should redirect to a different location or how to preserve the credit given without the link?


Discussion:
Thanks for reporting @jesseakt. Those credits should be removed, they don't belong in user docs. We have commit messages (fine here) or THANKS.txt for that.

Resolving patch:
diff --git a/numpy/doc/subclassing.py b/numpy/doc/subclassing.py
--- a/numpy/doc/subclassing.py
+++ b/numpy/doc/subclassing.py
@@ -3,12 +3,6 @@
 Subclassing ndarray in python
 =============================
 
-Credits
--------
-
-This page is based with thanks on the wiki page on subclassing by Pierre
-Gerard-Marchant - http://www.scipy.org/Subclasses.
-
 Introduction
 ------------
 


Test patch:
Repository: numpy/numpy

Issue:
ENH: matrix_rank should support stacks of matrices
"Several of the linear algebra routines listed above are able to compute results for several matrices at once, if they are stacked into the same array." ([Linalg documentation](http://docs.scipy.org/doc/numpy/reference/routines.linalg.html#linear-algebra-on-several-matrices-at-once))

However, `matrix_rank` is limited to a single matrix even though it is implemented using `linalg.svd` which supports stacks of matrices.



Discussion:

Resolving patch:
diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py
--- a/numpy/linalg/linalg.py
+++ b/numpy/linalg/linalg.py
@@ -1516,8 +1516,8 @@ def matrix_rank(M, tol=None):
 
     Parameters
     ----------
-    M : {(M,), (M, N)} array_like
-        array of <=2 dimensions
+    M : {(M,), (..., M, N)} array_like
+        input vector or stack of matrices
     tol : {None, float}, optional
        threshold below which SVD values are considered zero. If `tol` is
        None, and ``S`` is an array with singular values for `M`, and
@@ -1584,14 +1584,12 @@ def matrix_rank(M, tol=None):
     0
     """
     M = asarray(M)
-    if M.ndim > 2:
-        raise TypeError('array should have 2 or fewer dimensions')
     if M.ndim < 2:
         return int(not all(M==0))
     S = svd(M, compute_uv=False)
     if tol is None:
-        tol = S.max() * max(M.shape) * finfo(S.dtype).eps
-    return sum(S > tol)
+        tol = S.max(axis=-1, keepdims=True) * max(M.shape[-2:]) * finfo(S.dtype).eps
+    return (S > tol).sum(axis=-1)
 
 
 # Generalized inverse


Test patch:
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -1261,8 +1261,9 @@ def test_matrix_rank(self):
         yield assert_equal, matrix_rank(np.zeros((4,))), 0
         # accepts array-like
         yield assert_equal, matrix_rank([1]), 1
-        # greater than 2 dimensions raises error
-        yield assert_raises, TypeError, matrix_rank, np.zeros((2, 2, 2))
+        # greater than 2 dimensions treated as stacked matrices
+        ms = np.array([I, np.eye(4), np.zeros((4,4))])
+        yield assert_equal, matrix_rank(ms), np.array([3, 4, 0])
         # works on scalar
         yield assert_equal, matrix_rank(1), 1
Repository: numpy/numpy

Issue:
np.hstack([ ]) throws IndexError instead of ValueError
Calling `np.hstack([ ])` throws an `IndexError`. It takes a bit more work to find out the root cause of the error, ie: the empty list.
```
>>> import numpy as np
>>> np.hstack([ ])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 277, in hstack
    if arrs[0].ndim == 1:
IndexError: list index out of range
```

`np.vstack`, on the other hand, throws a more appropriate error.

```
>>> np.vstack([ ])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 230, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: need at least one array to concatenate
```



Discussion:
I will take this. Thanks!
@eric-wieser What error message would you prefer to use there? 
How about `ValueError: need at least one element to concatenate`?

And if it is acceptable to add 
`if len(arrs) == 0:
        raise ValueError('need at least one element to concatenate')`
before the line [if arrs[0].ndim == 1:](https://github.com/numpy/numpy/blob/master/numpy/core/shape_base.py#L286)?

Resolving patch:
diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py
--- a/numpy/core/shape_base.py
+++ b/numpy/core/shape_base.py
@@ -283,7 +283,7 @@ def hstack(tup):
     """
     arrs = [atleast_1d(_m) for _m in tup]
     # As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
-    if arrs[0].ndim == 1:
+    if arrs and arrs[0].ndim == 1:
         return _nx.concatenate(arrs, 0)
     else:
         return _nx.concatenate(arrs, 1)


Test patch:
diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py
--- a/numpy/core/tests/test_shape_base.py
+++ b/numpy/core/tests/test_shape_base.py
@@ -123,6 +123,9 @@ class TestHstack(TestCase):
     def test_non_iterable(self):
         assert_raises(TypeError, hstack, 1)
 
+    def test_empty_input(self):
+        assert_raises(ValueError, hstack, ())
+
     def test_0D_array(self):
         a = array(1)
         b = array(2)
@@ -149,6 +152,9 @@ class TestVstack(TestCase):
     def test_non_iterable(self):
         assert_raises(TypeError, vstack, 1)
 
+    def test_empty_input(self):
+        assert_raises(ValueError, vstack, ())
+
     def test_0D_array(self):
         a = array(1)
         b = array(2)
Repository: numpy/numpy

Issue:
numpy.diff fails on unsigned integers (Trac #1929)
_Original ticket http://projects.scipy.org/numpy/ticket/1929 on 2011-08-10 by trac user tlatorre, assigned to unknown._

It appears numpy.diff insists on returning an array of the same datatype as the input which is incorrect for unsigned integers.

> > > np.diff(np.array([3,2], dtype=np.uint8))
> > > array([255], dtype=uint8)
> > > np.diff(np.array([1,0], dtype=np.uint16))
> > > array([65535], dtype=uint16)
> > > np.diff(np.array([3,2,0], dtype=np.uint32))
> > > array([4294967295, 4294967294], dtype=uint32)
> > > np.diff(np.array([3,2,0], dtype=np.uint64))
> > > array([18446744073709551615, 18446744073709551614], dtype=uint64)



Discussion:
_@charris wrote on 2011-08-13_

Subtracting unsigned numbers from each other is a well defined operation, so this is a case of user beware. However, it is probably not what is expected. I think adding a note to the doc string and maybe an example would clarify things. Or we could raise a warning. In the latter case there should first be some discussion on the mailing list. 


Resolving patch:
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1874,6 +1874,23 @@ def diff(a, n=1, axis=-1):
     will contain `False` when consecutive elements are the same and
     `True` when they differ.
 
+    For unsigned integer arrays, the results will also be unsigned. This should
+    not be surprising, as the result is consistent with calculating the
+    difference directly:
+
+    >>> u8_arr = np.array([1, 0], dtype=np.uint8)
+    >>> np.diff(u8_arr)
+    array([255], dtype=uint8)
+    >>> u8_arr[1,...] - u8_arr[0,...]
+    array(255, np.uint8)
+
+    If this is not desirable, then the array should be cast to a larger integer
+    type first:
+
+    >>> i16_arr = u8_arr.astype(np.int16)
+    >>> np.diff(i16_arr)
+    array([-1], dtype=int16)
+
     Examples
     --------
     >>> x = np.array([1, 2, 4, 7, 0])


Test patch: