Skip to content

[BUG]: create_violin() failure with numpy==2.24.0: TypeError: percentile() got an unexpected keyword argument 'interpolation' #5461

@mgorny

Description

@mgorny

Description

The TestViolin.test_violin_fig reveals that the create_violin() function is failing against numpy==2.4.0. It passes after downgrading to <2.4.0.

========================================================= test session starts =========================================================
platform linux -- Python 3.12.12, pytest-9.0.2, pluggy-1.6.0
rootdir: /tmp/plotly.py
configfile: pyproject.toml
plugins: anyio-4.12.1, typeguard-4.4.4, timeout-2.4.0
collected 1 item                                                                                                                      

tests/test_optional/test_figure_factory/test_figure_factory.py F                                                                [100%]

============================================================== FAILURES ===============================================================
_____________________________________________________ TestViolin.test_violin_fig ______________________________________________________

self = <tests.test_optional.test_figure_factory.test_figure_factory.TestViolin testMethod=test_violin_fig>

    def test_violin_fig(self):
        # check: test violin fig matches expected fig
    
>       test_violin = ff.create_violin(data=[1, 2])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/test_optional/test_figure_factory/test_figure_factory.py:2313: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
plotly/figure_factory/_violin.py:603: in create_violin
    plot_data, plot_xrange = violinplot(
plotly/figure_factory/_violin.py:163: in violinplot
    vals_min = calc_stats(vals)["min"]
               ^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

data = array([1., 2.])

    def calc_stats(data):
        """
        Calculate statistics for use in violin plot.
        """
        x = np.asarray(data, float)
        vals_min = np.min(x)
        vals_max = np.max(x)
>       q2 = np.percentile(x, 50, interpolation="linear")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       TypeError: percentile() got an unexpected keyword argument 'interpolation'

plotly/figure_factory/_violin.py:20: TypeError
======================================================= short test summary info =======================================================
FAILED tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig - TypeError: percentile() got an unexpected keyword argument 'interpolation'
========================================================== 1 failed in 2.99s ==========================================================

Steps to reproduce

uv venv -p 3.12
uv pip install -e .[dev]
.venv/bin/pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions