From 7dc40b1587fa76362550df4aaab529dbb72fdac9 Mon Sep 17 00:00:00 2001 From: Mayk Thewessen Date: Mon, 12 Oct 2026 14:44:11 +0200 Subject: [PATCH] fix: type check with numpy 2.5.4 isscalar stubs numpy 2.5.4 widened the TypeIs of np.isscalar to include numbers.Number, which xarray's DataArray.__add__ does not accept, so mypy fails on the legacy scalar branch of _add_constant. Cast to the scalar members of ConstantLike; no runtime change. Co-Authored-By: Claude Opus 5.5 --- linopy/expressions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linopy/expressions.py b/linopy/expressions.py index 197482ad..e0414483 100644 --- a/linopy/expressions.py +++ b/linopy/expressions.py @@ -1275,7 +1275,9 @@ def _add_constant_legacy( if is_nan_scalar(other): check_user_nan() warn_legacy_absence(self.const) - return self.assign(const=self.const.fillna(0) + other) + return self.assign( + const=self.const.fillna(0) + cast("float | np.number", other) + ) self_const, da, needs_reindex = self._broadcast_and_align( other, fill_value, join )