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

Make test suite ready for NumPy 2.0.0 #4622

Merged
merged 19 commits into from
Nov 7, 2024
Merged

Conversation

bnavigator
Copy link
Contributor

The soon to be released NumPy 2.0.0 removes some aliases of np.nan and np.inf, so these must be removed from the tests in order to keep the test suite green.

Also, when testing data with small integer types like int8, the literals need to be cast beforehand in order to avoid overflow errors.

References

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

@marthacryan
Copy link
Collaborator

@bnavigator Is it okay if I push some changes here to handle both versions of numpy?

@bnavigator
Copy link
Contributor Author

@bnavigator Is it okay if I push some changes here to handle both versions of numpy?

Yes, of course. Sorry I do not have time to enhance it myself right now.

@gvwilson gvwilson added feature something new P1 needed for current cycle community community contribution labels Aug 13, 2024
@gvwilson gvwilson assigned gvwilson and unassigned marthacryan Oct 24, 2024
@marthacryan marthacryan force-pushed the np2 branch 2 times, most recently from e79e2d6 to c9bdfbe Compare November 1, 2024 17:41
@natsukium
Copy link

Thanks for tackling this issue.
I get the following error when using numpy2, do you know what it is?
Please let me know if this should be a separate issue/pr.
I haven't dived into the codebase yet, so I'll report back if I find out anything.

plotly/tests/test_optional/test_utils/test_utils.py::test_masked_constants_example fails with RecursionError: maximum recursion depth exceeded with numpy 2.1.2.

====================================================================================================== test session starts =======================================================================================================
platform linux -- Python 3.12.4, pytest-8.3.3, pluggy-1.5.0
rootdir: /root/plotly.py/packages/python/plotly
configfile: pytest.ini
collected 26 items                                                                                                                                                                                                               

plotly/tests/test_optional/test_utils/test_utils.py .........................F                                                                                                                                             [100%]

============================================================================================================ FAILURES ============================================================================================================
_________________________________________________________________________________________________ test_masked_constants_example __________________________________________________________________________________________________

    @pytest.mark.matplotlib
    def test_masked_constants_example():
        try:
            pd.options.plotting.backend = "matplotlib"
        except Exception:
            pass
    
        # example from: https://gist.github.com/tschaume/d123d56bf586276adb98
        data = {
            "esN": [0, 1, 2, 3],
            "ewe_is0": [-398.11901997, -398.11902774, -398.11897111, -398.11882215],
            "ewe_is1": [-398.11793027, -398.11792966, -398.11786308, None],
            "ewe_is2": [-398.11397008, -398.11396421, None, None],
        }
        df = pd.DataFrame.from_dict(data)
    
        plotopts = {"x": "esN"}
        fig, ax = plt.subplots(1, 1)
>       df.plot(ax=ax, **plotopts)

plotly/tests/test_optional/test_utils/test_utils.py:456: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.12/site-packages/pandas/plotting/_core.py:1030: in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/__init__.py:71: in plot
    plot_obj.generate()
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/core.py:501: in generate
    self._make_plot(fig)
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/core.py:1550: in _make_plot
    newlines = plotf(
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/core.py:1586: in _plot
    lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/converter.py:95: in wrapper
    return func(*args, **kwargs)
/usr/local/lib/python3.12/site-packages/pandas/plotting/_matplotlib/core.py:966: in _plot
    y = np.ma.array(y)
/usr/local/lib/python3.12/site-packages/numpy/__init__.py:346: in __getattr__
    import numpy.ma as ma
/usr/local/lib/python3.12/site-packages/numpy/__init__.py:346: in __getattr__
    import numpy.ma as ma
E   RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)

@gvwilson gvwilson assigned marthacryan and unassigned gvwilson Nov 5, 2024
@marthacryan
Copy link
Collaborator

Thanks for tackling this issue. I get the following error when using numpy2, do you know what it is? Please let me know if this should be a separate issue/pr. I haven't dived into the codebase yet, so I'll report back if I find out anything.

I'm also seeing this error - you can see it's happening in the CI as well. I'm currently trying to investigate but if you figure anything out let me know!

@marthacryan
Copy link
Collaborator

The recursion error is fixed! 🎉

Copy link
Contributor

@archmoj archmoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@marthacryan marthacryan merged commit 6319ab9 into plotly:master Nov 7, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution feature something new P1 needed for current cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants