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

[FEATURE] NumPy 2.0 support #13835

Open
jakirkham opened this issue Apr 24, 2024 · 5 comments
Open

[FEATURE] NumPy 2.0 support #13835

jakirkham opened this issue Apr 24, 2024 · 5 comments
Milestone

Comments

@jakirkham
Copy link
Contributor

jakirkham commented Apr 24, 2024

Problem description

NumPy 2.0 is coming out soon ( numpy/numpy#24300 ). NumPy 2.0.0rc1 packages for conda & wheels came out 3 weeks back ( numpy/numpy#24300 (comment) )

Feature description

To prepare for NumPy 2.0, it might be worthwhile to start testing Bokeh against NumPy 2 in CI

Also as NumPy is tracking ecosystem support for NumPy 2.0, it would be helpful to share Bokeh's current support status in issue (with any plans): numpy/numpy#26191

NumPy has put out a migration guide. More details are in the release notes. As Bokeh doesn't have C/C++ usage of NumPy, only the Python changes would be relevant

Potential alternatives

In the short term, Bokeh may wish to set an upper bound on NumPy version until testing can happen. Alternatively Bokeh could wait for user issues and address as those come up

Maybe there are other options that haven't been considered here

Additional information

It appears Bokeh depends on ContourPy, which may also need updates. Filed upstream issue: contourpy/contourpy#378

@bryevdv bryevdv added type: task and removed TRIAGE labels Apr 24, 2024
@bryevdv bryevdv added this to the 3.5 milestone Apr 24, 2024
@bryevdv
Copy link
Member

bryevdv commented Apr 24, 2024

cc @bokeh/dev I have triaged this as task. For reference I tried several Bokeh server app examples with 2.0.0rc1 installed and they seemed work fine. Exceptions were:

  • image_blur.py is horrifically slow and unresponsive, but this seems to be the case regardless of numpy version. I will open a separate issue
  • contour_animated.py fails to display (but does work if numpy is downgraded) so my guess is contourpy might need and update (cc @ianthomas23)

@bryevdv
Copy link
Member

bryevdv commented Apr 24, 2024

There only seem to be a handful of relevant unit test failures

FAILED tests/unit/bokeh/core/property/test_validation__property.py::TestValidateDetailDefault::test_Bool - AssertionError: assert False
FAILED tests/unit/bokeh/plotting/test_contour.py::Test_contour_data::test_xy_dim[0] - ValueError: operands could not be broadcast together with shapes (1,1,0) (7,)
FAILED tests/unit/bokeh/plotting/test_contour.py::Test_contour_data::test_xy_dim[1] - ValueError: operands could not be broadcast together with shapes (1,1,0) (7,)
FAILED tests/unit/bokeh/plotting/test_contour.py::Test_contour_data::test_xy_dim[2] - ValueError: operands could not be broadcast together with shapes (1,1,0) (7,)
FAILED tests/unit/bokeh/plotting/test_contour.py::Test_from_contour::test_fill_line[True-True] - ValueError: operands could not be broadcast together with shapes (1,1,0) (7,)
FAILED tests/unit/bokeh/plotting/test_contour.py::Test_from_contour::test_fill_line[True-False] - ValueError: operands could not be broadcast together with shapes (1,1,0) (7,)

@ianthomas23
Copy link
Member

ContourPy 1.2.1 supports NumPy 2.0. For me, all the contour-based examples and tests work for bokeh >= 3.4.1, contourpy 1.2.1 and NumPy 2.0.0rc1.

@bryevdv I suspect you are trying to use ContourPy 1.2.0 (which does NOT support NumPy 2.0) rather than 1.2.1 here.

@bryevdv
Copy link
Member

bryevdv commented Apr 25, 2024

@ianthomas23 apparently so, I was testing things on two different machines, and only one of them had contourpy updated it seems. Contour examples and tests work fine now.

As of now I only see one failing unit test (on OSX) with 2.0.0rc1, and it does pass with 1.26 installed

==================================================== FAILURES ====================================================
______________________________________ TestValidateDetailDefault.test_Bool _______________________________________

self = <test_validation__property.TestValidateDetailDefault object at 0x104f3fce0>

    def test_Bool(self) -> None:
        p = Bool()
        with pytest.raises(ValueError) as e:
            p.validate("junk")
>       assert matches(str(e.value), r"expected a value of type bool or bool_, got junk of type str")
E       AssertionError: assert False
E        +  where False = matches('expected a value of type bool or bool, got junk of type str', 'expected a value of type bool or bool_, got junk of type str')
E        +    where 'expected a value of type bool or bool, got junk of type str' = str(ValueError('expected a value of type bool or bool, got junk of type str'))
E        +      where ValueError('expected a value of type bool or bool, got junk of type str') = <ExceptionInfo ValueError('expected a value of type bool or bool, got junk of type str') tblen=2>.value

tests/unit/bokeh/core/property/test_validation__property.py:134: AssertionError
============================================ short test summary info =============================================
FAILED tests/unit/bokeh/core/property/test_validation__property.py::TestValidateDetailDefault::test_Bool - AssertionError: assert False
========================================= 1 failed, 111 passed in 0.33s ==========================================

@bryevdv
Copy link
Member

bryevdv commented Apr 25, 2024

Switching to use the match param of pytest.raises (we should update all the tests this way) provides the connection to numpy for this test:

    def test_Bool(self) -> None:
        p = Bool()
>       with pytest.raises(ValueError, match=r"expected a value of type bool or bool_, got junk of type str"):
E       AssertionError: Regex pattern did not match.
E        Regex: 'expected a value of type bool or bool_, got junk of type str'
E        Input: 'expected a value of type bool or bool, got junk of type str'

I will try to stand up a CI job with 2.0.0rc if this is the only failure then we should cut a 3.4.2 soon.

Edit: actually if this is the only failure, then I think we could claim that released 3.4.1 already supports numpy 2.0 since this is just the text of the error message and not the exception.

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

No branches or pull requests

3 participants