Skip to content

BUG: TestNanFunctions_Median.test_keepdims_out #22835

@bnavigator

Description

@bnavigator

Describe the issue:

The random matrices for TestNanFunctions_Median.test_keepdims_out fail to slice ocassionally while building numpy 1.24 for openSUSE Tumbleweed.

Reproduce the code example:

import numpy as np
np.test(extra_argv=['-k', 'test_keepdims_out'])

Error message:

[ 2386s] _________________ TestNanFunctions_Median.test_keepdims_out[1] _________________
[ 2386s] [gw7] linux -- Python 3.8.16 /usr/bin/python3.8
[ 2386s] 
[ 2386s] self = <numpy.lib.tests.test_nanfunctions.TestNanFunctions_Median object at 0x7f07bc2c7520>
[ 2386s] axis = 1
[ 2386s] 
[ 2386s]     @pytest.mark.parametrize(
[ 2386s]         argnames='axis',
[ 2386s]         argvalues=[
[ 2386s]             None,
[ 2386s]             1,
[ 2386s]             (1, ),
[ 2386s]             (0, 1),
[ 2386s]             (-3, -1),
[ 2386s]         ]
[ 2386s]     )
[ 2386s]     def test_keepdims_out(self, axis):
[ 2386s]         d = np.ones((3, 5, 7, 11))
[ 2386s]         # Randomly set some elements to NaN:
[ 2386s]         w = np.random.random((4, 200)) * np.array(d.shape)[:, None]
[ 2386s]         w = w.astype(np.intp)
[ 2386s]         d[tuple(w)] = np.nan
[ 2386s]         if axis is None:
[ 2386s]             shape_out = (1,) * d.ndim
[ 2386s]         else:
[ 2386s]             axis_norm = normalize_axis_tuple(axis, d.ndim)
[ 2386s]             shape_out = tuple(
[ 2386s]                 1 if i in axis_norm else d.shape[i] for i in range(d.ndim))
[ 2386s]         out = np.empty(shape_out)
[ 2386s] >       result = np.nanmedian(d, axis=axis, keepdims=True, out=out)
[ 2386s] 
[ 2386s] axis       = 1
[ 2386s] axis_norm  = (1,)
[ 2386s] d          = array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ....1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1., nan,  1.]]]])
[ 2386s] out        = array([[[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-...73875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26]]]])
[ 2386s] self       = <numpy.lib.tests.test_nanfunctions.TestNanFunctions_Median object at 0x7f07bc2c7520>
[ 2386s] shape_out  = (3, 1, 7, 11)
[ 2386s] w          = array([[ 0,  1,  1,  1,  2,  1,  0,  0,  1,  1,  1,  1,  2,  2,  2,  0,
[ 2386s]          2,  1,  0,  0,  2,  0,  2,  1,  2,  0...,  9,
[ 2386s]          3,  4,  1, 10,  2, 10,  3,  6,  3,  7,  7, 10,  5,  3,  7,  0,
[ 2386s]          6,  0,  9,  9,  8,  6,  0,  1]])
[ 2386s] 
[ 2386s] ../../../BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/lib/tests/test_nanfunctions.py:834: 
[ 2386s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[ 2386s] <__array_function__ internals>:200: in nanmedian
[ 2386s]     ???
[ 2386s]         args       = (array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ..., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1., nan,  1.]]]]),)
[ 2386s]         dispatcher = <function _nanmedian_dispatcher at 0x7f07c61a59d0>
[ 2386s]         implementation = <function nanmedian at 0x7f07c61a5af0>
[ 2386s]         kwargs     = {'axis': 1, 'keepdims': True, 'out': array([[[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.6367387...3875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26]]]])}
[ 2386s]         public_api = <function nanmedian at 0x7f07c61a5b80>
[ 2386s]         relevant_args = (array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ...3875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26]]]]))
[ 2386s] ../../../BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/lib/nanfunctions.py:1217: in nanmedian
[ 2386s]     return function_base._ureduce(a, func=_nanmedian, keepdims=keepdims,
[ 2386s]         a          = array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ....1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1., nan,  1.]]]])
[ 2386s]         axis       = 1
[ 2386s]         keepdims   = True
[ 2386s]         out        = array([[[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-...73875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26]]]])
[ 2386s]         overwrite_input = False
[ 2386s] ../../../BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/lib/function_base.py:3752: in _ureduce
[ 2386s]     r = func(a, **kwargs)
[ 2386s]         a          = array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ....1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1., nan,  1.]]]])
[ 2386s]         axis       = (1,)
[ 2386s]         func       = <function _nanmedian at 0x7f07c61a58b0>
[ 2386s]         index_out  = (slice(None, None, None), 0, slice(None, None, None), slice(None, None, None))
[ 2386s]         keepdims   = True
[ 2386s]         kwargs     = {'axis': 1, 'out': array([[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-...3673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26]]]), 'overwrite_input': False}
[ 2386s]         nd         = 4
[ 2386s]         out        = array([[[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-...73875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]           -8.63673875e-26, -8.63673875e-26]]]])
[ 2386s] ../../../BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/lib/nanfunctions.py:1094: in _nanmedian
[ 2386s]     return _nanmedian_small(a, axis, out, overwrite_input)
[ 2386s]         a          = array([[[[ 1., nan,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ..., nan,  1.,  1.],
[ 2386s]          [nan,  1.,  1., ....1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1.,  1.,  1.],
[ 2386s]          [ 1.,  1.,  1., ...,  1., nan,  1.]]]])
[ 2386s]         axis       = 1
[ 2386s]         out        = array([[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26...63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26]]])
[ 2386s]         overwrite_input = False
[ 2386s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[ 2386s] 
[ 2386s] a = masked_array(
[ 2386s]   data=[[[[1.0, --, 1.0, ..., 1.0, 1.0, 1.0],
[ 2386s]           [1.0, 1.0, 1.0, ..., --, 1.0, 1.0],
[ 2386s]           [-...se, False, ..., False, False, False],
[ 2386s]           [False, False, False, ..., False,  True, False]]]],
[ 2386s]   fill_value=1e+20)
[ 2386s] axis = 1
[ 2386s] out = array([[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26...63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26]]])
[ 2386s] overwrite_input = False
[ 2386s] 
[ 2386s]     def _nanmedian_small(a, axis=None, out=None, overwrite_input=False):
[ 2386s]         """
[ 2386s]         sort + indexing median, faster for small medians along multiple
[ 2386s]         dimensions due to the high overhead of apply_along_axis
[ 2386s]     
[ 2386s]         see nanmedian for parameter usage
[ 2386s]         """
[ 2386s]         a = np.ma.masked_array(a, np.isnan(a))
[ 2386s]         m = np.ma.median(a, axis=axis, overwrite_input=overwrite_input)
[ 2386s]         for i in range(np.count_nonzero(m.mask.ravel())):
[ 2386s] >           warnings.warn("All-NaN slice encountered", RuntimeWarning,
[ 2386s]                           stacklevel=4)
[ 2386s] E           RuntimeWarning: All-NaN slice encountered
[ 2386s] 
[ 2386s] a          = masked_array(
[ 2386s]   data=[[[[1.0, --, 1.0, ..., 1.0, 1.0, 1.0],
[ 2386s]           [1.0, 1.0, 1.0, ..., --, 1.0, 1.0],
[ 2386s]           [-...se, False, ..., False, False, False],
[ 2386s]           [False, False, False, ..., False,  True, False]]]],
[ 2386s]   fill_value=1e+20)
[ 2386s] axis       = 1
[ 2386s] i          = 0
[ 2386s] m          = masked_array(
[ 2386s]   data=[[[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[ 2386s]          [1.0, 1.0, 1.0, 1.0, 1.0, 1.0...         [False, False, False, False, False, False, False, False, False,
[ 2386s]           False, False]]],
[ 2386s]   fill_value=1e+20)
[ 2386s] out        = array([[[-8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26...63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26, -8.63673875e-26,
[ 2386s]          -8.63673875e-26, -8.63673875e-26]]])
[ 2386s] overwrite_input = False
[ 2386s] 
[ 2386s] ../../../BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/lib/nanfunctions.py/home/abuild/rpmbuild/BUILDROOT/python-numpy-1.24.0-124.1.x86_64/usr/lib64/python3.8/site-packages/numpy/_pytesttester.py:143: DeprecationWarning: 
[ 2386s] 
[ 2386s]   `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
[ 2386s]   of the deprecation of `distutils` itself. It will be removed for
[ 2386s]   Python >= 3.12. For older Python versions it will remain present.
[ 2386s]   It is recommended to use `setuptools < 60.0` for those Python versions.
[ 2386s]   For more details, see:
[ 2386s]     https://numpy.org/devdocs/reference/distutils_status_migration.html 
[ 2386s] 
[ 2386s] 
[ 2386s]   from numpy.distutils import cpuinfo
[ 2386s] :1111: RuntimeWarning
[ 2386s] =========================== short test summary info ============================
[ 2386s] FAILED lib/tests/test_nanfunctions.py::TestNanFunctions_Median::test_keepdims_out[1]
[ 2386s] = 1 failed, 23068 passed, 2238 skipped, 35 xfailed, 3 xpassed in 436.92s (0:07:16) =

NumPy/Python version information:

1.24.0 3.10.9 (main, Dec 08 2022, 14:49:06) [GCC]

Context for the issue:

This is a flaky issue. Sometimes the test passes, sometimes not. On different parametrizations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions