Skip to content
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

MAINT, TST: failure in test_axis_nan_policy_decorated_positional_args with array API #20661

Closed
tylerjereddy opened this issue May 8, 2024 · 2 comments · Fixed by #20663
Closed
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.stats
Milestone

Comments

@tylerjereddy
Copy link
Contributor

I regularly run the full array API suite locally, but can be reproduced with focused call as well: python dev.py test -t scipy/stats/tests/test_axis_nan_policy.py::test_axis_nan_policy_decorated_positional_args -b all

___________________________________________________________________________________________________________ test_axis_nan_policy_decorated_positional_args ___________________________________________________________________________________________________________
scipy/stats/tests/test_axis_nan_policy.py:585: in test_axis_nan_policy_decorated_positional_args
    stats.kruskal(samples=x)
        message    = "kruskal() got an unexpected keyword argument 'samples'"
        rng        = Generator(PCG64) at 0x7FF32ED32180
        shape      = (3, 8, 9, 10)
        x          = array([[[[           nan, 2.69786714e-01, 4.09735239e-02, ...,
          7.29496561e-01, 5.43624991e-01, 9.35072424e-0...    [6.60372970e-01, 9.65276732e-02, 1.06143803e-01, ...,
          3.86779163e-01, 9.80181895e-01, 1.39465441e-01]]]])
scipy/stats/_axis_nan_policy.py:494: in axis_nan_policy_wrapper
    samples = _broadcast_arrays(samples, axis=axis)
        _no_deco   = False
        axis       = 0
        d_args     = {}
        default_axis = 0
        hypotest_fun_in = <function kruskal at 0x7ff3381de020>
        hypotest_fun_out = <function kruskal at 0x7ff3381de020>
        intersection = set()
        is_too_small = <function _axis_nan_policy_factory.<locals>.is_too_small at 0x7ff3381ddee0>
        keepdims   = False
        kwd_samp   = []
        kwd_samples = []
        kwds       = {'samples': array([[[[           nan, 2.69786714e-01, 4.09735239e-02, ...,
          7.29496561e-01, 5.43624991e-01, 9...   [6.60372970e-01, 9.65276732e-02, 1.06143803e-01, ...,
          3.86779163e-01, 9.80181895e-01, 1.39465441e-01]]]])}
        maxarg     = inf
        n_kwd_samp = 0
        n_out      = 2
        n_outputs  = 2
        n_samp     = 0
        n_samples  = None
        nan_policy = 'propagate'
        override   = {'nan_propagation': True, 'vectorization': False}
        paired     = False
        params     = ['nan_policy']
        reduced_axes = 0
        result_to_tuple = <function _axis_nan_policy_factory.<locals>.result_to_tuple at 0x7ff3381dde40>
        samples    = []
        sentinel   = None
        temp       = []
        tuple_to_result = <class 'scipy.stats._stats_py.KruskalResult'>
        used_kwd_samples = []
        vectorized = False
scipy/stats/_axis_nan_policy.py:19: in _broadcast_arrays
    xp = array_namespace(*arrays) if xp is None else xp
        arrays     = []
        axis       = 0
        xp         = None
scipy/_lib/_array_api.py:128: in array_namespace
    return array_api_compat.array_namespace(*_arrays)
        _arrays    = []
        arrays     = ()
scipy/_lib/array_api_compat/common/_helpers.py:283: in array_namespace
    raise TypeError("Unrecognized array input")
E   TypeError: Unrecognized array input
        _use_compat = True
        api_version = None
        namespaces = set()
        xs         = ()

During handling of the above exception, another exception occurred:
scipy/stats/tests/test_axis_nan_policy.py:584: in test_axis_nan_policy_decorated_positional_args
    with pytest.raises(TypeError, match=re.escape(message)):
E   AssertionError: Regex pattern did not match.
E    Regex: "kruskal\\(\\)\\ got\\ an\\ unexpected\\ keyword\\ argument\\ 'samples'"
E    Input: 'Unrecognized array input'
        message    = "kruskal() got an unexpected keyword argument 'samples'"
        rng        = Generator(PCG64) at 0x7FF32ED32180
        shape      = (3, 8, 9, 10)
        x          = array([[[[           nan, 2.69786714e-01, 4.09735239e-02, ...,
          7.29496561e-01, 5.43624991e-01, 9.35072424e-0...    [6.60372970e-01, 9.65276732e-02, 1.06143803e-01, ...,
          3.86779163e-01, 9.80181895e-01, 1.39465441e-01]]]])

@mdhaber maybe this slipped through? Or am I doing something wrong.

@tylerjereddy tylerjereddy added scipy.stats maintenance Items related to regular maintenance tasks array types Items related to array API support and input array validation (see gh-18286) labels May 8, 2024
@mdhaber
Copy link
Contributor

mdhaber commented May 8, 2024

I have been seeing that, and I thought we fixed it already in a PR or have a PR open with a fix. IIRC it started when we changed _get_nan. It's an edge case nicety - it's checking for a particular error message but it's getting another. I'll take another look.

@mdhaber
Copy link
Contributor

mdhaber commented May 8, 2024

Ths comes up because a function that accepts a variable number of positional arguments gets zero positional arguments. Now that we're adding array_namespace very early in the execution of a lot of functions, functions that handled the no-arg case gracefully in the past now start to get the error message that array_namespace wants to raise. This has come up in at least two different ways so far, so I'll make sure a test like this runs in the array API job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) maintenance Items related to regular maintenance tasks scipy.stats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants