Skip to content

fix: newaxis indexing#151

Draft
terraputix wants to merge 1 commit into
mainfrom
fix/newaxis-indexing
Draft

fix: newaxis indexing#151
terraputix wants to merge 1 commit into
mainfrom
fix/newaxis-indexing

Conversation

@terraputix

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes NumPy-style None/np.newaxis indexing for OmFileReader (and the async reader) by tracking NewAxis positions during index parsing and re-inserting size-1 dimensions after applying integer-index squeezing. It also adds a suite of Python tests for basic indexing semantics.

Changes:

  • Extend ArrayIndex::get_ranges_and_squeeze_dims to return newaxis_dims in addition to read ranges and squeeze_dims.
  • Update sync/async readers to apply newaxis_dims when reshaping the returned ndarray.
  • Add Python indexing tests (integer/slice/ellipsis/negative slice/newaxis/mixed/errors) and additional Rust unit tests for NewAxis parsing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/test_read_write.py Adds comprehensive indexing tests and NewAxis-specific assertions.
src/reader.rs Plumbs newaxis_dims into array read/reshape path; updates an fsspec TypeError message.
src/reader_async.rs Mirrors sync reader changes by passing newaxis_dims into async reshape logic.
src/array_index.rs Enhances index parsing to track NewAxis positions and adjust squeeze/newaxis dims appropriately.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/array_index.rs
Comment on lines 201 to +215
squeeze_dims.sort_by(|a, b| b.cmp(a));

Ok((ranges, squeeze_dims))
// Adjust squeeze_dims from output space to read-array space:
// each NewAxis before a squeeze dim shifts it left by 1.
for pos in squeeze_dims.iter_mut() {
let shift = newaxis_dims.iter().filter(|&&n| n < *pos).count();
*pos -= shift;
}

// Adjust newaxis_dims from output space to post-squeeze space:
// each squeezed dim before a NewAxis shifts it left by 1.
for pos in newaxis_dims.iter_mut() {
let shift = squeeze_dims.iter().filter(|&&s| s < *pos).count();
*pos -= shift;
}
Comment thread tests/test_read_write.py
Comment on lines +510 to +518
ref = _ref_data()
reader = omfiles.OmFileReader(temp_om_file)
np.testing.assert_array_equal(reader[None], ref[None])
np.testing.assert_array_equal(reader[None, :3], ref[None, :3])
np.testing.assert_array_equal(reader[1, None], ref[1, None])
np.testing.assert_array_equal(reader[None, 1], ref[None, 1])
np.testing.assert_array_equal(reader[None, None], ref[None, None])
np.testing.assert_array_equal(reader[..., None], ref[..., None])
np.testing.assert_array_equal(reader[None, ...], ref[None, ...])
Comment thread tests/test_read_write.py
Comment on lines +520 to +522


def test_indexing_mixed(temp_om_file):
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