Skip to content

chore: fix typing with new highspy version#795

Merged
FabianHofmann merged 2 commits into
PyPSA:masterfrom
fluxopt:fix/highs-integrality-uint8
Jun 29, 2026
Merged

chore: fix typing with new highspy version#795
FabianHofmann merged 2 commits into
PyPSA:masterfrom
fluxopt:fix/highs-integrality-uint8

Conversation

@FBumann

@FBumann FBumann commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

mypy fix due to tightened stubs in highspy 1.15

Note

This change was generated by AI.

The direct-solve HiGHS path built the integrality array as int32 and passed it to changeColsIntegrality, whose var_types argument expects a uint8 array — matching HiGHS's uint8-backed HighsVarType enum (Continuous=0, Integer=1, SemiContinuous=2, …).

Recent highspy (1.13.1) tightened its type stubs to require uint8 here, which surfaces as a mypy error:

linopy/solvers.py: error: Argument 3 to "changeColsIntegrality" ...
  has incompatible type "ndarray[..., dtype[signedinteger[_32Bit]]]";
  expected "ndarray[..., dtype[unsignedinteger[_8Bit]]]"

The persistent in-place update path (_apply_var_types) already builds this array as uint8; this aligns the direct-solve path. uint8 is accepted at runtime across highspy versions, so this is a safe correctness fix, not a version workaround.

highspy's changeColsIntegrality expects var_types as a uint8 array
(matching HiGHS's uint8-backed HighsVarType enum). The persistent
update path already builds it as uint8 (_apply_var_types); align the
direct-solve path so it matches highspy's tightened type stubs and is
robust across versions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codspeed-hq

codspeed-hq Bot commented Jun 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 138 untouched benchmarks
⏩ 138 skipped benchmarks1


Comparing fluxopt:fix/highs-integrality-uint8 (d4dcafe) with master (2d47d4a)

Open in CodSpeed

Footnotes

  1. 138 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

highspy is imported under TYPE_CHECKING, so mypy types `highspy` as the
module; assigning the `_LazyModule` shim then trips [assignment] once
highspy ships recognized types (highspy 1.13.1). Mirror the existing
gurobipy line with `# type: ignore[assignment]`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@FBumann FBumann changed the title fix(highs): pass uint8 integrality array to changeColsIntegrality chore: fix typing with new highspy version Jun 29, 2026
@FBumann FBumann requested a review from FabianHofmann June 29, 2026 08:58
@FBumann

FBumann commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

I canceled pypsa run to save ci minutes

@FabianHofmann FabianHofmann merged commit 4ddf3fb into PyPSA:master Jun 29, 2026
23 of 24 checks passed
@FBumann FBumann deleted the fix/highs-integrality-uint8 branch June 29, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants