Commit d5a82a2
refactor: move alignment code to linopy/alignment.py; restructure tests (#742)
* refactor: move conversion/broadcasting/alignment code to linopy/alignment.py
Pure move, no behavior change. The new module owns the seam between user
input and linopy's labelled arrays:
- coords parsing: _coords_to_dict, _as_index, _as_multiindex
- conversion: get_from_iterable, pandas_to_dataarray, numpy_to_dataarray,
_named_pandas_to_dataarray, fill_missing_coords, as_dataarray
- MultiIndex projection: _LevelProjection, _project_onto_multiindex_levels,
_warn_implicit_projections
- broadcasting: _broadcast_to_coords, broadcast_to_coords
- validation: validate_alignment
- symmetric alignment: align
common.py keeps the general utilities (formatting, label indexes, polars
helpers, decorators). Importers (model, expressions, variables, __init__,
tests) updated; no re-exports.
Follow-up requested by @FabianHofmann in #732.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test: restructure alignment tests into test_alignment.py
One class per concept in linopy.alignment, mirroring the module's public
surface:
- TestAsDataarrayFrom{Pandas,Numpy,Scalar,DataArray} + MultiIndexCoords
- TestCoordsToDict (the coords-entry naming rules)
- TestBroadcastToCoords (strict=False mechanics)
- TestMultiIndexProjection (projection values, deprecation warnings,
coverage gaps — the legacy/v1 fork point for #717)
- TestStrictMode (strict=True contract)
- TestValidateAlignment
- TestAlign
Shared fixtures (mi_index / mi_coords / by_level1) replace the repeated
MultiIndex setup; the pandas dims-naming and numpy labeling tests are
consolidated into parametrized tables. test_common.py keeps the utility
tests. Full suite count unchanged (3202) — no coverage lost.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test: close coverage gaps in alignment.py and the MI coords serialization
alignment.py: 97% -> 99%. New edge-case tests: bare-string dims, 0-d
arrays, fill_missing_coords type check, partially-named MI levels,
gap detection with extra dims, gap-error truncation (>5 missing
combinations). The two remaining uncovered lines are defensive branches
for inputs outside the DimsLike contract (non-iterable dims).
common.py: 88% -> 90%. The MultiIndex round-trip through
coords_to_dataset_vars / coords_from_dataset (used by CSRConstraint)
had zero coverage; now pinned.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Update test/test_alignment.py
Co-authored-by: Fabian Hofmann <fab.hof@gmx.de>
* Update test/test_alignment.py
Co-authored-by: Fabian Hofmann <fab.hof@gmx.de>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Fabian Hofmann <fab.hof@gmx.de>1 parent f4af3f1 commit d5a82a2
9 files changed
Lines changed: 1926 additions & 1823 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
0 commit comments