Skip to content

BUG: stats.mode: failure with array of Pandas integers #18254

@josef-pkt

Description

@josef-pkt

Describe your issue.

Another pre-test failure in statsmodels unit testing

https://github.com/scipy/scipy/pull/17561/files#diff-c850dba4f9919cabafa6e3ffbc1d0c61cf315d1e06755a867317fd891f9e2aaaR580
added [()] to results which looks like it breaks if the value is already a scalar

from failing unit test https://dev.azure.com/statsmodels/statsmodels-testing/_build/results?buildId=5078&view=logs&j=aabc21e9-9439-578e-0393-ea6ef34c273c&t=3c5b382f-2ffe-594f-225e-664c15c6a882

        # `axis`, `nan_policy`, and `keepdims` are handled by `_axis_nan_policy`
    
        if a.size == 0:
            return ModeResult(np.nan, np.int64(0))
    
        vals, cnts = np.unique(a, return_counts=True)
        modes, counts = vals[cnts.argmax()], cnts.max()
>       return ModeResult(modes[()], counts[()])
E       TypeError: 'int' object is not subscriptable

This goes from statsmodels through pandas and then scipy.stats

I cannot extract the example (with pdb) because I don't have dev versions installed

Reproducing Code Example

-

Error message

-

SciPy/NumPy/Python version and system information

scipy main

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues related to the SciPy documentation. Also check https://github.com/scipy/scipy.orgdefectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.stats

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions