Skip to content

Add ArrayEntry dataclass and add_array_entries method#102

Merged
cmutel merged 2 commits into
mainfrom
feat/array-entry
Jun 4, 2026
Merged

Add ArrayEntry dataclass and add_array_entries method#102
cmutel merged 2 commits into
mainfrom
feat/array-entry

Conversation

@cmutel
Copy link
Copy Markdown
Member

@cmutel cmutel commented Jun 4, 2026

Summary

  • Adds ArrayEntry, a lightweight dataclass that holds all row/col index pairs, a 2-D scenario data array, and an optional flip array for one persistent-array resource group — avoiding the decompose-and-reassemble pattern that would arise from using MatrixEntry row-by-row
  • Adds Datapackage.add_array_entries(*, matrix, entries: list[ArrayEntry]) as the high-level convenience wrapper around add_persistent_array, creating one resource group per entry
  • Exports ArrayEntry from the public API via __init__.py
  • Validates shape consistency in ArrayEntry.__post_init__: rows must be 1-D, cols must match rows shape, data must be 2-D with row count matching rows, flip must match rows shape if provided

Test plan

  • TestArrayEntry — 8 unit tests covering construction, numpy inputs, and all validation error paths
  • TestAddArrayEntries — 6 integration tests covering single/multiple entries, indices/data/flip storage, and absence of flip resource when not provided
  • Full test suite: pytest tests/test_matrix_entry.py (36 passed)

cmutel added 2 commits June 4, 2026 09:13
Introduces ArrayEntry, a lightweight dataclass holding all index/flip
metadata for one persistent-array resource group, avoiding the
decompose-and-reassemble pattern that would arise from using MatrixEntry
row-by-row. Adds Datapackage.add_array_entries() as the high-level
convenience wrapper around add_persistent_array, and exports ArrayEntry
from the public API. Includes validation on shape consistency and 14 new
tests.
…rayEntry

- ArrayEntry.__post_init__ now stores normalized numpy arrays back to
  self.rows/cols/data/flip so fields are always ndarray after construction
- Add integer dtype check on rows/cols to prevent silent float truncation
  when constructing the INDICES_DTYPE structured array
- Coerce flip to dtype=bool at construction time, avoiding data-dependent
  WrongDatatype crashes in add_persistent_array
- add_array_entries now uses direct field assignment to build indices
  (np.empty + indices['row']/['col']) instead of list(zip(...)), removing
  the intermediate Python-level allocation and redundant np.asarray calls
- Add 4 tests covering the new validation and normalization paths
@cmutel cmutel merged commit af2de3e into main Jun 4, 2026
6 checks passed
@cmutel cmutel deleted the feat/array-entry branch June 4, 2026 07:40
@cmutel cmutel mentioned this pull request Jun 4, 2026
3 tasks
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.

1 participant