Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Invalid docstring for numpy.fix (?) #27257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serge-sans-paille opened this issue Aug 21, 2024 · 10 comments · Fixed by #27262
Closed

DOC: Invalid docstring for numpy.fix (?) #27257

serge-sans-paille opened this issue Aug 21, 2024 · 10 comments · Fixed by #27262
Assignees

Comments

@serge-sans-paille
Copy link
Contributor

Issue with current documentation:

The documentation for numpy.fix states it returns a float for integral values, but running the actual code make it return an integral value:

$ python -c 'from numpy.version import full_version; import numpy; print(full_version); print(numpy.fix.__doc__); print(numpy.fix(3))'                                                                                                                                                                         
2.1.0

    Round to nearest integer towards zero.

    Round an array of floats element-wise to nearest integer towards zero.
    The rounded values are returned as floats.

    Parameters
    ----------
    x : array_like
        An array of floats to be rounded
    out : ndarray, optional
        A location into which the result is stored. If provided, it must have
        a shape that the input broadcasts to. If not provided or None, a
        freshly-allocated array is returned.

    Returns
    -------
    out : ndarray of floats
        A float array with the same dimensions as the input.
        If second argument is not supplied then a float array is returned
        with the rounded values.

        If a second argument is supplied the result is stored there.
        The return value `out` is then a reference to that array.

    See Also
    --------
    rint, trunc, floor, ceil
    around : Round to given number of decimals

    Examples
    --------
    >>> import numpy as np
    >>> np.fix(3.14)
    3.0
    >>> np.fix(3)
    3.0
    >>> np.fix([2.1, 2.9, -2.1, -2.9])
    array([ 2.,  2., -2., -2.])

    
3

In addition to this unconsistency, it worries me that docstring would be invalid... does that mean we're not running doctest?

Idea or request for content:

No response

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Aug 21, 2024

The behavior was changed by #26766. The change in behavior of floor, ceil and trunc was noted in the 2.1.0 release notes. fix changed because it is implemented using floor and ceil.

Doesn't that change in behavior potentially break backwards compatibility for users expecting a float return type from all these functions?

@serge-sans-paille
Copy link
Contributor Author

Thanks for the pointer. I'm personally fine with the change, but the patch you're pointing at doesn't update documentation, right?

@WarrenWeckesser
Copy link
Member

Right. The docs need to be updated to reflect the change in behavior.

@ngoldbaum
Copy link
Member

Ping @mtsokol. Would you mind updating the docs here? Maybe also a new release note for 2.1.1?

@mtsokol
Copy link
Member

mtsokol commented Aug 21, 2024

@ngoldbaum Sure!

@mtsokol mtsokol self-assigned this Aug 21, 2024
@mtsokol mtsokol added this to the 2.1.1 release milestone Aug 21, 2024
@serge-sans-paille
Copy link
Contributor Author

does it mean doctest is not run on the docstring?

@ngoldbaum
Copy link
Member

ngoldbaum commented Aug 21, 2024

It looks like the doctest for numpy.fix passes when I run spin check-docs:

numpy/__init__.py::numpy.fix PASSED                             [ 12%]

@ev-br do you happen to know why scipy_doctest isn't catching this?

@ev-br
Copy link
Contributor

ev-br commented Aug 21, 2024

the "doctester" calls np.allclose (https://github.com/scipy/scipy_doctest/blob/main/scipy_doctest/impl.py#L388), and

>>> np.fix(3)
np.int64(3)
>>> np.allclose(np.int64(3), 3.0)
True

I suppose the tool can get a "be stricter" flag to check dtypes, too.

EDIT: In fact, it's even more basic: there's an equality check before np.allclose, and

>>> np.int64(3) == 3.0
np.True_

mtsokol added a commit to mtsokol/numpy that referenced this issue Aug 21, 2024
mtsokol added a commit to mtsokol/numpy that referenced this issue Aug 21, 2024
@mtsokol mtsokol linked a pull request Aug 21, 2024 that will close this issue
@mattip
Copy link
Member

mattip commented Aug 21, 2024

So there are really two issues here: the documentation is not up to date, and doctests do not check dtype (and maybe other array attributes). I will open a new issue about doctests.

@ev-br
Copy link
Contributor

ev-br commented Aug 23, 2024

First experiments: apparently there are numpy objects which are equal but not np.allclose:

In [4]: np.allclose('abc', np.str_('abc'))
---------------------------------------------------------------------------
DTypePromotionError                       Traceback (most recent call last)
Cell In[4], line 1
----> 1 np.allclose('abc', np.str_('abc'))


DTypePromotionError: The DType <class 'numpy.dtypes.StrDType'> could not be promoted by <class 'numpy.dtypes._PyFloatDType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtypes.StrDType'>, <class 'numpy.dtypes._PyFloatDType'>)

In [5]: 'abc' == np.str_('abc')
Out[5]: True

This related because the OP is due to

>>> np.int64(3) == 3.0
np.True_
================================================ FAILURES ================================================
__________________________________________ [doctest] numpy.str_ __________________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> s
Expected:
    'abc'
Got:
    np.str_('abc')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
_________________________________________ [doctest] numpy.append _________________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> c.dtype
Expected:
    float64
Got:
    dtype('float64')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
____________________________________ [doctest] numpy.char.capitalize _____________________________________
1109         depending on input types
1110 
1111     See Also
1112     --------
1113     str.capitalize
1114 
1115     Examples
1116     --------
1117     >>> import numpy as np
1118     >>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c
Expected:
    array(['a1b2', '1b2a', 'b2a1', '2a1b'],
        dtype='|S4')
Got:
    array([b'a1b2', b'1b2a', b'b2a1', b'2a1b'], dtype='|S4')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1118: DocTestFailure
______________________________________ [doctest] numpy.char.lstrip _______________________________________
865 
866     See Also
867     --------
868     str.lstrip
869 
870     Examples
871     --------
872     >>> import numpy as np
873     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
874     >>> c
Expected:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
    # The 'a' variable is unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:874: DocTestFailure
_______________________________________ [doctest] numpy.char.strip _______________________________________
956     --------
957     str.strip
958 
959     Examples
960     --------
961     >>> import numpy as np
962     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
963     >>> c
964     array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
965     >>> np.strings.strip(c)
Expected:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
    # 'a' unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:965: DocTestFailure
_____________________________________ [doctest] numpy.char.swapcase ______________________________________
1070         depending on input types
1071 
1072     See Also
1073     --------
1074     str.swapcase
1075 
1076     Examples
1077     --------
1078     >>> import numpy as np
1079     >>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c
Expected:
    array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'],
        dtype='|S5')
Got:
    array([b'a1B c', b'1b Ca', b'b Ca1', b'cA1b'], dtype='|S5')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1079: DocTestFailure
_______________________________________ [doctest] numpy.char.title _______________________________________
1150         depending on input types
1151 
1152     See Also
1153     --------
1154     str.title
1155 
1156     Examples
1157     --------
1158     >>> import numpy as np
1159     >>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c
Expected:
    array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
        dtype='|S5')
Got:
    array([b'a1b c', b'1b ca', b'b ca1', b'ca1b'], dtype='|S5')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1159: DocTestFailure
______________________________ [doctest] numpy.core.defchararray.capitalize ______________________________
1109         depending on input types
1110 
1111     See Also
1112     --------
1113     str.capitalize
1114 
1115     Examples
1116     --------
1117     >>> import numpy as np
1118     >>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c
Expected:
    array(['a1b2', '1b2a', 'b2a1', '2a1b'],
        dtype='|S4')
Got:
    array([b'a1b2', b'1b2a', b'b2a1', b'2a1b'], dtype='|S4')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1118: DocTestFailure
________________________________ [doctest] numpy.core.defchararray.lstrip ________________________________
865 
866     See Also
867     --------
868     str.lstrip
869 
870     Examples
871     --------
872     >>> import numpy as np
873     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
874     >>> c
Expected:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
    # The 'a' variable is unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:874: DocTestFailure
________________________________ [doctest] numpy.core.defchararray.strip _________________________________
956     --------
957     str.strip
958 
959     Examples
960     --------
961     >>> import numpy as np
962     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
963     >>> c
964     array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
965     >>> np.strings.strip(c)
Expected:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
    # 'a' unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:965: DocTestFailure
_______________________________ [doctest] numpy.core.defchararray.swapcase _______________________________
1070         depending on input types
1071 
1072     See Also
1073     --------
1074     str.swapcase
1075 
1076     Examples
1077     --------
1078     >>> import numpy as np
1079     >>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c
Expected:
    array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'],
        dtype='|S5')
Got:
    array([b'a1B c', b'1b Ca', b'b Ca1', b'cA1b'], dtype='|S5')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1079: DocTestFailure
________________________________ [doctest] numpy.core.defchararray.title _________________________________
1150         depending on input types
1151 
1152     See Also
1153     --------
1154     str.title
1155 
1156     Examples
1157     --------
1158     >>> import numpy as np
1159     >>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c
Expected:
    array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
        dtype='|S5')
Got:
    array([b'a1b c', b'1b ca', b'b ca1', b'ca1b'], dtype='|S5')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1159: DocTestFailure
___________________________________ [doctest] numpy.core.numeric.str_ ____________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> s
Expected:
    'abc'
Got:
    np.str_('abc')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
_________________________________ [doctest] numpy.core.numerictypes.str_ _________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> s
Expected:
    'abc'
Got:
    np.str_('abc')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
_______________________________ [doctest] numpy.core.records.format_parser _______________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.rec.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
??? ...                      []).dtype
Expected:
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
Got:
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', 'S5')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/rec/__init__.py:None: DocTestFailure
___________________________________ [doctest] numpy.dtypes.StringDType ___________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.array(["hello", "world"], dtype=StringDType())
Expected:
    array(["hello", "world"], dtype=StringDType())
Got:
    array(['hello', 'world'], dtype=StringDType())

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/dtypes.py:None: DocTestFailure
______________________________ [doctest] numpy.lib.introspect.opt_func_info ______________________________
029     --------
030     Retrieve dispatch information for functions named 'add' or 'sub' and
031     data types 'float64' or 'float32':
032 
033     >>> import numpy as np
034     >>> dict = np.lib.introspect.opt_func_info(
035     ...     func_name="add|abs", signature="float64|complex64"
036     ... )
037     >>> import json
038     >>> print(json.dumps(dict, indent=2))
Differences (unified diff with -expected +actual):
    @@ -1,26 +1,26 @@
    -    {
    -      "absolute": {
    -        "dd": {
    -          "current": "SSE41",
    -          "available": "SSE41 baseline(SSE SSE2 SSE3)"
    -        },
    -        "Ff": {
    -          "current": "FMA3__AVX2",
    -          "available": "AVX512F FMA3__AVX2 baseline(SSE SSE2 SSE3)"
    -        },
    -        "Dd": {
    -          "current": "FMA3__AVX2",
    -          "available": "AVX512F FMA3__AVX2 baseline(SSE SSE2 SSE3)"
    -        }
    -      },
    -      "add": {
    -        "ddd": {
    -          "current": "FMA3__AVX2",
    -          "available": "FMA3__AVX2 baseline(SSE SSE2 SSE3)"
    -        },
    -        "FFF": {
    -          "current": "FMA3__AVX2",
    -          "available": "FMA3__AVX2 baseline(SSE SSE2 SSE3)"
    -        }
    -      }
    +{
    +  "absolute": {
    +    "dd": {
    +      "current": "SSE41",
    +      "available": "SSE41 baseline(SSE SSE2 SSE3)"
    +    },
    +    "Ff": {
    +      "current": "AVX2",
    +      "available": "AVX512F AVX2 baseline(SSE SSE2 SSE3)"
    +    },
    +    "Dd": {
    +      "current": "AVX2",
    +      "available": "AVX512F AVX2 baseline(SSE SSE2 SSE3)"
         }
    +  },
    +  "add": {
    +    "ddd": {
    +      "current": "AVX2",
    +      "available": "AVX2 baseline(SSE SSE2 SSE3)"
    +    },
    +    "FFF": {
    +      "current": "AVX2",
    +      "available": "AVX2 baseline(SSE SSE2 SSE3)"
    +    }
    +  }
    +}

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/lib/introspect.py:38: DocTestFailure
_____________________________ [doctest] numpy.lib.recfunctions.merge_arrays ______________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> rfn.merge_arrays((np.array([1, 2], dtype=np.int64),
??? ...         np.array([10., 20., 30.])), usemask=False)
Expected:
     array([(1, 10.0), (2, 20.0), (-1, 30.0)],
             dtype=[('f0', '<i8'), ('f1', '<f8')])
Got:
    array([( 1, 10.), ( 2, 20.), (-1, 30.)],
          dtype=[('f0', '<i8'), ('f1', '<f8')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/lib/recfunctions.py:None: DocTestFailure
_____________________________ [doctest] numpy.lib.recfunctions.repack_fields _____________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> dt
Expected:
    dtype({'names': ['f0', 'f1', 'f2'], 'formats': ['u1', '<i8', '<f8'], 'offsets': [0, 8, 16], 'itemsize': 24}, align=True)
Got:
    dtype([('f0', 'u1'), ('f1', '<i8'), ('f2', '<f8')], align=True)

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/lib/recfunctions.py:None: DocTestFailure
_______________________________________ [doctest] numpy.ma.is_mask _______________________________________
1557     >>> m
1558     array([False,  True, False])
1559     >>> ma.is_mask(m)
1560     True
1561 
1562     Arrays with complex dtypes don't return True.
1563 
1564     >>> dtype = np.dtype({'names':['monty', 'pithon'],
1565     ...                   'formats':[bool, bool]})
1566     >>> dtype
Expected:
    dtype([('monty', '|b1'), ('pithon', '|b1')])
Got:
    dtype([('monty', '?'), ('pithon', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1566: DocTestFailure
______________________________________ [doctest] numpy.ma.make_mask ______________________________________
1651     ...     arr.append((man, mouse))
1652     >>> arr
1653     [(1, 0), (0, 1), (1, 0), (1, 0)]
1654     >>> dtype = np.dtype({'names':['man', 'mouse'],
1655     ...                   'formats':[np.int64, np.int64]})
1656     >>> arr = np.array(arr, dtype=dtype)
1657     >>> arr
1658     array([(1, 0), (0, 1), (1, 0), (1, 0)],
1659           dtype=[('man', '<i8'), ('mouse', '<i8')])
1660     >>> ma.make_mask(arr, dtype=dtype)
Expected:
    array([(True, False), (False, True), (True, False), (True, False)],
          dtype=[('man', '|b1'), ('mouse', '|b1')])
Got:
    array([( True, False), (False,  True), ( True, False), ( True, False)],
          dtype=[('man', '?'), ('mouse', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1660: DocTestFailure
___________________________________ [doctest] numpy.ma.make_mask_descr ___________________________________
1379 
1380     Examples
1381     --------
1382     >>> import numpy as np
1383     >>> import numpy.ma as ma
1384     >>> dtype = np.dtype({'names':['foo', 'bar'],
1385     ...                   'formats':[np.float32, np.int64]})
1386     >>> dtype
1387     dtype([('foo', '<f4'), ('bar', '<i8')])
1388     >>> ma.make_mask_descr(dtype)
Expected:
    dtype([('foo', '|b1'), ('bar', '|b1')])
Got:
    dtype([('foo', '?'), ('bar', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1388: DocTestFailure
___________________________________ [doctest] numpy.ma.make_mask_none ____________________________________
1714     >>> ma.make_mask_none((3,))
1715     array([False, False, False])
1716 
1717     Defining a more complex dtype.
1718 
1719     >>> dtype = np.dtype({'names':['foo', 'bar'],
1720     ...                   'formats':[np.float32, np.int64]})
1721     >>> dtype
1722     dtype([('foo', '<f4'), ('bar', '<i8')])
1723     >>> ma.make_mask_none((3,), dtype=dtype)
Expected:
    array([(False, False), (False, False), (False, False)],
          dtype=[('foo', '|b1'), ('bar', '|b1')])
Got:
    array([(False, False), (False, False), (False, False)],
          dtype=[('foo', '?'), ('bar', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1723: DocTestFailure
____________________________________ [doctest] numpy.ma.clump_masked _____________________________________
2272     --------
2273     flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
2274     notmasked_contiguous, clump_unmasked
2275 
2276     Examples
2277     --------
2278     >>> import numpy as np
2279     >>> a = np.ma.masked_array(np.arange(10))
2280     >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
2281     >>> np.ma.clump_masked(a)
Expected:
    [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]
Got:
    [slice(0, np.int64(3), None), slice(np.int64(6), np.int64(7), None), slice(np.int64(8), 10, None)]

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/extras.py:2281: DocTestFailure
___________________________________ [doctest] numpy.ma.clump_unmasked ____________________________________
2232     --------
2233     flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
2234     notmasked_contiguous, clump_masked
2235 
2236     Examples
2237     --------
2238     >>> import numpy as np
2239     >>> a = np.ma.masked_array(np.arange(10))
2240     >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
2241     >>> np.ma.clump_unmasked(a)
Expected:
    [slice(3, 6, None), slice(7, 8, None)]
Got:
    [slice(np.int64(3), np.int64(6), None), slice(np.int64(7), np.int64(8), None)]

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/extras.py:2241: DocTestFailure
____________________________________ [doctest] numpy.ma.core.is_mask _____________________________________
1557     >>> m
1558     array([False,  True, False])
1559     >>> ma.is_mask(m)
1560     True
1561 
1562     Arrays with complex dtypes don't return True.
1563 
1564     >>> dtype = np.dtype({'names':['monty', 'pithon'],
1565     ...                   'formats':[bool, bool]})
1566     >>> dtype
Expected:
    dtype([('monty', '|b1'), ('pithon', '|b1')])
Got:
    dtype([('monty', '?'), ('pithon', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1566: DocTestFailure
___________________________________ [doctest] numpy.ma.core.make_mask ____________________________________
1651     ...     arr.append((man, mouse))
1652     >>> arr
1653     [(1, 0), (0, 1), (1, 0), (1, 0)]
1654     >>> dtype = np.dtype({'names':['man', 'mouse'],
1655     ...                   'formats':[np.int64, np.int64]})
1656     >>> arr = np.array(arr, dtype=dtype)
1657     >>> arr
1658     array([(1, 0), (0, 1), (1, 0), (1, 0)],
1659           dtype=[('man', '<i8'), ('mouse', '<i8')])
1660     >>> ma.make_mask(arr, dtype=dtype)
Expected:
    array([(True, False), (False, True), (True, False), (True, False)],
          dtype=[('man', '|b1'), ('mouse', '|b1')])
Got:
    array([( True, False), (False,  True), ( True, False), ( True, False)],
          dtype=[('man', '?'), ('mouse', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1660: DocTestFailure
________________________________ [doctest] numpy.ma.core.make_mask_descr _________________________________
1379 
1380     Examples
1381     --------
1382     >>> import numpy as np
1383     >>> import numpy.ma as ma
1384     >>> dtype = np.dtype({'names':['foo', 'bar'],
1385     ...                   'formats':[np.float32, np.int64]})
1386     >>> dtype
1387     dtype([('foo', '<f4'), ('bar', '<i8')])
1388     >>> ma.make_mask_descr(dtype)
Expected:
    dtype([('foo', '|b1'), ('bar', '|b1')])
Got:
    dtype([('foo', '?'), ('bar', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1388: DocTestFailure
_________________________________ [doctest] numpy.ma.core.make_mask_none _________________________________
1714     >>> ma.make_mask_none((3,))
1715     array([False, False, False])
1716 
1717     Defining a more complex dtype.
1718 
1719     >>> dtype = np.dtype({'names':['foo', 'bar'],
1720     ...                   'formats':[np.float32, np.int64]})
1721     >>> dtype
1722     dtype([('foo', '<f4'), ('bar', '<i8')])
1723     >>> ma.make_mask_none((3,), dtype=dtype)
Expected:
    array([(False, False), (False, False), (False, False)],
          dtype=[('foo', '|b1'), ('bar', '|b1')])
Got:
    array([(False, False), (False, False), (False, False)],
          dtype=[('foo', '?'), ('bar', '?')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/core.py:1723: DocTestFailure
_________________________________ [doctest] numpy.ma.extras.clump_masked _________________________________
2272     --------
2273     flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
2274     notmasked_contiguous, clump_unmasked
2275 
2276     Examples
2277     --------
2278     >>> import numpy as np
2279     >>> a = np.ma.masked_array(np.arange(10))
2280     >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
2281     >>> np.ma.clump_masked(a)
Expected:
    [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]
Got:
    [slice(0, np.int64(3), None), slice(np.int64(6), np.int64(7), None), slice(np.int64(8), 10, None)]

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/extras.py:2281: DocTestFailure
________________________________ [doctest] numpy.ma.extras.clump_unmasked ________________________________
2232     --------
2233     flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
2234     notmasked_contiguous, clump_masked
2235 
2236     Examples
2237     --------
2238     >>> import numpy as np
2239     >>> a = np.ma.masked_array(np.arange(10))
2240     >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
2241     >>> np.ma.clump_unmasked(a)
Expected:
    [slice(3, 6, None), slice(7, 8, None)]
Got:
    [slice(np.int64(3), np.int64(6), None), slice(np.int64(7), np.int64(8), None)]

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/ma/extras.py:2241: DocTestFailure
______________________________________ [doctest] numpy.matlib.str_ _______________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> s
Expected:
    'abc'
Got:
    np.str_('abc')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
_____________________________________ [doctest] numpy.matlib.append ______________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> c.dtype
Expected:
    float64
Got:
    dtype('float64')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/__init__.py:None: DocTestFailure
___________________________________ [doctest] numpy.rec.format_parser ____________________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.rec.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
??? ...                      []).dtype
Expected:
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
Got:
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', 'S5')])

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/rec/__init__.py:None: DocTestFailure
_____________________________________ [doctest] numpy.strings.lstrip _____________________________________
865 
866     See Also
867     --------
868     str.lstrip
869 
870     Examples
871     --------
872     >>> import numpy as np
873     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
874     >>> c
Expected:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
    # The 'a' variable is unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:874: DocTestFailure
_____________________________________ [doctest] numpy.strings.strip ______________________________________
956     --------
957     str.strip
958 
959     Examples
960     --------
961     >>> import numpy as np
962     >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
963     >>> c
964     array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
965     >>> np.strings.strip(c)
Expected:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
    # 'a' unstripped from c[1] because of leading whitespace.
Got:
    array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:965: DocTestFailure
____________________________________ [doctest] numpy.strings.swapcase ____________________________________
1070         depending on input types
1071 
1072     See Also
1073     --------
1074     str.swapcase
1075 
1076     Examples
1077     --------
1078     >>> import numpy as np
1079     >>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c
Expected:
    array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'],
        dtype='|S5')
Got:
    array([b'a1B c', b'1b Ca', b'b Ca1', b'cA1b'], dtype='|S5')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1079: DocTestFailure
___________________________________ [doctest] numpy.strings.capitalize ___________________________________
1109         depending on input types
1110 
1111     See Also
1112     --------
1113     str.capitalize
1114 
1115     Examples
1116     --------
1117     >>> import numpy as np
1118     >>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c
Expected:
    array(['a1b2', '1b2a', 'b2a1', '2a1b'],
        dtype='|S4')
Got:
    array([b'a1b2', b'1b2a', b'b2a1', b'2a1b'], dtype='|S4')

/home/br/repos/numpy/build-install/usr/lib/python3.11/site-packages/numpy/_core/strings.py:1118: DocTestFailure
_____________________________________ [doctest] numpy.strings.title ______________________________________
1150         depending on input types
1151 
1152     See Also
1153     --------
1154     str.title
1155 
1156     Examples
1157     --------
1158     >>> import numpy as np
1159     >>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c
Expected:
    array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
        dtype='|S5')
Got:
    array([b'a1b c', b'1b ca', b'b ca1', b'ca1b'], dtype='|S5')

```

charris added a commit that referenced this issue Aug 23, 2024
charris pushed a commit to charris/numpy that referenced this issue Aug 24, 2024
charris added a commit that referenced this issue Aug 24, 2024
@charris charris removed this from the 2.1.1 release milestone Aug 28, 2024
ArvidJB pushed a commit to ArvidJB/numpy that referenced this issue Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants