Skip to content

MaskedNDArray.sort() got an unexpected keyword argument 'descending' + array compare failure #19760

Closed

Description

@pllim

Suspect upstream PR:

________________________ TestArgFunctions.test_argsort _________________________

self = <astropy.units.tests.test_quantity_non_ufuncs.TestArgFunctions object at 0x7f1c67637e10>

    def test_argsort(self):
>       self.check(np.argsort)

astropy/units/tests/test_quantity_non_ufuncs.py:209: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <astropy.units.tests.test_quantity_non_ufuncs.TestArgFunctions object at 0x7f1c67637e10>
func = <function argsort at 0x7f1c97d829f0>, args = (), kwargs = {}
out = <Quantity [[0, 1, 2],
           [0, 1, 2],
           [0, 1, 2]] m>
expected = array([[0, 1, 2],
       [0, 1, 2],
       [0, 1, 2]])
@py_assert2 = <class 'astropy.units.quantity.Quantity'>
@py_assert7 = <class 'numpy.ndarray'>, @py_assert4 = False
@py_format9 = "<class 'astropy.units.quantity.Quantity'>\n{<class 'astropy.units.quantity.Quantity'> = type(<Quantity [[0, 1, 2],\\n...class 'numpy.ndarray'>\n{<class 'numpy.ndarray'> = type(array([[0, 1, 2],\\n       [0, 1, 2],\\n       [0, 1, 2]]))\n}"
@py_format11 = "assert <class 'astropy.units.quantity.Quantity'>\n{<class 'astropy.units.quantity.Quantity'> = type(<Quantity [[0, 1,...class 'numpy.ndarray'>\n{<class 'numpy.ndarray'> = type(array([[0, 1, 2],\\n       [0, 1, 2],\\n       [0, 1, 2]]))\n}"

    def check(self, func, *args, **kwargs):
        out = func(self.q, *args, **kwargs)
        expected = func(self.q.value, *args, *kwargs)
>       assert type(out) is type(expected)
E       AssertionError: assert <class 'astropy.units.quantity.Quantity'> is <class 'numpy.ndarray'>
E        +  where <class 'astropy.units.quantity.Quantity'> = type(<Quantity [[0, 1, 2],\n           [0, 1, 2],\n           [0, 1, 2]] m>)
E        +  and   <class 'numpy.ndarray'> = type(array([[0, 1, 2],\n       [0, 1, 2],\n       [0, 1, 2]]))

astropy/units/tests/test_quantity_non_ufuncs.py:93: AssertionError
________________________ TestArgFunctions.test_argsort _________________________

self = <astropy.utils.masked.tests.test_function_helpers.TestArgFunctions object at 0x7f1c6b1d63f0>

    def test_argsort(self):
>       self.check(np.argsort, fill_value=np.nan)

astropy/utils/masked/tests/test_function_helpers.py:177: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <astropy.utils.masked.tests.test_function_helpers.TestArgFunctions object at 0x7f1c6b1d63f0>
function = <function argsort at 0x7f1c97d829f0>, fill_value = nan, args = ()
kwargs = {}, o = MaskedNDArray([[0, 1, 2],
               [0, 1, 2]])
a_filled = array([[nan,  1.,  2.],
       [ 3., nan,  5.]])
expected = array([[1, 2, 0],
       [0, 2, 1]])

    def check(self, function, *args, fill_value=np.nan, **kwargs):
        o = function(self.ma, *args, **kwargs)
        a_filled = self.ma.filled(fill_value=fill_value)
        expected = function(a_filled, *args, **kwargs)
>       assert_array_equal(o, expected)
E       AssertionError: 
E       Arrays are not equal
E       
E       Mismatched elements: 5 / 6 (83.3%)
E       Mismatch at indices:
E        [0, 0]: 0 (ACTUAL), 1 (DESIRED)
E        [0, 1]: 1 (ACTUAL), 2 (DESIRED)
E        [0, 2]: 2 (ACTUAL), 0 (DESIRED)
E        [1, 1]: 1 (ACTUAL), 2 (DESIRED)
E        [1, 2]: 2 (ACTUAL), 1 (DESIRED)
E       Max absolute difference among violations: 2
E       Max relative difference among violations: 1.
E        ACTUAL: MaskedNDArray([[0, 1, 2],
E                      [0, 1, 2]])
E        DESIRED: array([[1, 2, 0],
E              [0, 2, 1]])

astropy/utils/masked/tests/test_function_helpers.py:168: AssertionError
_________________________ TestSortFunctions.test_sort __________________________

self = <astropy.utils.masked.tests.test_function_helpers.TestSortFunctions object at 0x7f1c6a9db250>

    def test_sort(self):
>       o = np.sort(self.ma)
            ^^^^^^^^^^^^^^^^

astropy/utils/masked/tests/test_function_helpers.py:1199: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/utils/masked/core.py:1015: in __array_function__
    return super().__array_function__(function, types, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = MaskedNDArray([[——, 1., 2.],
               [3., ——, 5.]]), axis = -1
kind = None, order = None

    @array_function_dispatch(_sort_dispatcher)
    def sort(a, axis=-1, kind=None, order=None, *, stable=None, descending=None):
...
        if axis is None:
            # flatten returns (1, N) for np.matrix, so always use the last axis
            a = asanyarray(a).flatten()
            axis = -1
        else:
            a = asanyarray(a).copy(order="K")
>       a.sort(axis=axis, kind=kind, order=order, stable=stable, descending=descending)
E       TypeError: MaskedNDArray.sort() got an unexpected keyword argument 'descending'

numpy/_core/fromnumeric.py:1101: TypeError

Activity

  1. pllim commented on May 18, 2026

    @pllim
    Author
  2. mhvk commented on May 19, 2026

    @mhvk
    Contributor

    I think the problem is indeed upstream (though we should adjust appropriately later), thanks for tackling it!

  3. pllim commented on May 19, 2026

    @pllim
    MemberAuthor

    I am afraid to build numpy from source. Do you think numpy/numpy#31458 would completely fix everything here without further action from us?

  4. pllim commented on May 19, 2026

    @pllim
    MemberAuthor

    Upstream PR was merged, so now we wait for the "nightly" wheel to land and see if devdeps would be green again. 🤞

  5. pllim commented on May 20, 2026

    @pllim
    MemberAuthor

    devdeps is green!

  6. mhvk commented on May 20, 2026

    @mhvk
    Contributor

    Hurray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions