From e1dbace478f869d51fa5a09afb873c06bf288ecf Mon Sep 17 00:00:00 2001 From: hannah Date: Thu, 13 Feb 2025 19:20:12 -0500 Subject: [PATCH] Backport PR #29616: FIX: Fix unit example so that we can unpin numpy<2.1 --- .circleci/config.yml | 2 +- environment.yml | 2 +- galleries/examples/units/basic_units.py | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e7348b868d4b..40ba933cf0d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -98,7 +98,7 @@ commands: parameters: numpy_version: type: string - default: "~=2.0.0" + default: "" steps: - run: name: Install Python dependencies diff --git a/environment.yml b/environment.yml index 4a36f76031ea..8c4221d0a0fa 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - kiwisolver>=1.3.1 - pybind11>=2.13.2 - meson-python>=0.13.1 - - numpy<2.1 + - numpy - pillow>=8 - pkg-config - pygobject diff --git a/galleries/examples/units/basic_units.py b/galleries/examples/units/basic_units.py index 3f64d145b65e..486918a8eafc 100644 --- a/galleries/examples/units/basic_units.py +++ b/galleries/examples/units/basic_units.py @@ -193,6 +193,11 @@ def get_unit(self): class BasicUnit: + # numpy scalars convert eager and np.float64(2) * BasicUnit('cm') + # would thus return a numpy scalar. To avoid this, we increase the + # priority of the BasicUnit. + __array_priority__ = np.float64(0).__array_priority__ + 1 + def __init__(self, name, fullname=None): self.name = name if fullname is None: