Add ArrayEntry dataclass and add_array_entries method#102
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArrayEntry, a lightweight dataclass that holds all row/col index pairs, a 2-D scenariodataarray, and an optionalfliparray for one persistent-array resource group — avoiding the decompose-and-reassemble pattern that would arise from usingMatrixEntryrow-by-rowDatapackage.add_array_entries(*, matrix, entries: list[ArrayEntry])as the high-level convenience wrapper aroundadd_persistent_array, creating one resource group per entryArrayEntryfrom the public API via__init__.pyArrayEntry.__post_init__:rowsmust be 1-D,colsmust matchrowsshape,datamust be 2-D with row count matchingrows,flipmust matchrowsshape if providedTest plan
TestArrayEntry— 8 unit tests covering construction, numpy inputs, and all validation error pathsTestAddArrayEntries— 6 integration tests covering single/multiple entries, indices/data/flip storage, and absence of flip resource when not providedpytest tests/test_matrix_entry.py(36 passed)