Skip to content

Adding shape validation for add_matrix_to_collection#4258

Merged
ktsitsi merged 19 commits intomainfrom
kt/SOMA-387/add-shape-validation-to-soma-io-add-functions
Oct 21, 2025
Merged

Adding shape validation for add_matrix_to_collection#4258
ktsitsi merged 19 commits intomainfrom
kt/SOMA-387/add-shape-validation-to-soma-io-add-functions

Conversation

@ktsitsi
Copy link
Copy Markdown
Collaborator

@ktsitsi ktsitsi commented Oct 1, 2025

Issue and/or context:
The SOMA specification defines strict requirements for the shape of layers within pre-defined collections:

X: (O, V)
obsm: (O, M)
varm: (V, M)
obsp: (O, O)
varp: (V, V)

Where O is the domain of obs.soma_joinid, V is the domain of var.soma_joinid in the containing SOMAMeasurement, and M is user-defined.

However, the soma.io.add_matrix_to_collection() and soma.io.add_X_layer() functions do not validate the shape of incoming matrices.
Changes:

  • Introducing an internal validation function for testing the shape of the incoming Layer/Matrix to be added in a SOMA measurement.
  • Tests for add_matrix_to_collection and add_X_layer

Notes for Reviewer:

**DEFAULT BEHAVIOR: schema_validation = True **

@ktsitsi ktsitsi requested review from bkmartinjr and jp-dark October 1, 2025 17:28
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (e21bff2) to head (b2f8ad5).
⚠️ Report is 36 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4258       +/-   ##
===========================================
+ Coverage   76.12%   89.45%   +13.32%     
===========================================
  Files         233       61      -172     
  Lines       32559     7176    -25383     
  Branches     1240        0     -1240     
===========================================
- Hits        24786     6419    -18367     
+ Misses       7349      757     -6592     
+ Partials      424        0      -424     
Flag Coverage Δ
libtiledbsoma ?
python 89.45% <96.96%> (+<0.01%) ⬆️
r ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
python_api 89.45% <96.96%> (+<0.01%) ⬆️
libtiledbsoma ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ktsitsi ktsitsi force-pushed the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch from 71f98e2 to b37b395 Compare October 1, 2025 19:33
@ktsitsi ktsitsi requested a review from aaronwolen October 1, 2025 20:13
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Copy link
Copy Markdown
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

target shape determination is based upon the axis dataframe, not X['data']

@ktsitsi ktsitsi force-pushed the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch from 727dddb to 260630c Compare October 7, 2025 17:05
@ktsitsi ktsitsi requested a review from bkmartinjr October 7, 2025 17:30
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/tests/test_basic_anndata_io.py
Copy link
Copy Markdown
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

Two items that definitely need fix:

  • obsp/varp checks are incorrect - see inline note
  • need to test pre-1.15 (old-style shape)
    There are other suggested fixes also noted inline

@ktsitsi ktsitsi requested a review from bkmartinjr October 7, 2025 20:11
Comment thread apis/python/tests/test_basic_anndata_io.py Outdated
Comment thread apis/python/tests/test_basic_anndata_io.py Outdated
Comment thread apis/python/HISTORY.md Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
@ktsitsi ktsitsi force-pushed the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch 2 times, most recently from 3d54161 to 6d6cb26 Compare October 10, 2025 19:07
@ktsitsi ktsitsi requested a review from jp-dark October 13, 2025 14:24
@ktsitsi ktsitsi force-pushed the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch from 6d6cb26 to 08cb444 Compare October 13, 2025 20:01
Comment thread apis/python/HISTORY.md Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
Comment thread apis/python/src/tiledbsoma/io/ingest.py Outdated
@ktsitsi ktsitsi requested a review from bkmartinjr October 14, 2025 15:12
Comment thread apis/python/src/tiledbsoma/io/ingest.py
Comment thread apis/python/tests/test_basic_anndata_io.py Outdated
Copy link
Copy Markdown
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

Couple of requests:

  1. Need a test case that covers pre-1.15 experiment, schema validation on, and a "good" layer being added. Ie. a case that should succeed
  2. The handling of pre-1.15 data appears to get the wrong result for its shape, so schema validation on an old Experiment will always fail. See inline comments on this bug.

@ktsitsi ktsitsi force-pushed the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch from d4917cd to 6e4f91e Compare October 20, 2025 18:34
@ktsitsi ktsitsi requested a review from bkmartinjr October 20, 2025 18:51
Comment thread apis/python/tests/test_basic_anndata_io.py Outdated
Copy link
Copy Markdown
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

Two tiny nits in the tests. Would be great if you can fix as they are super easy.

Otherwise, it LGTM.

@ktsitsi ktsitsi merged commit 2d91da6 into main Oct 21, 2025
12 checks passed
@ktsitsi ktsitsi deleted the kt/SOMA-387/add-shape-validation-to-soma-io-add-functions branch October 21, 2025 20:23
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 5, 2025

The backport to release-2.2 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release-2.2 release-2.2
# Navigate to the new working tree
cd .worktrees/backport-release-2.2
# Create a new branch
git switch --create backport-4258-to-release-2.2
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 2d91da66948febfcd128c6d27e90aa4227e27dc7
# Push it to GitHub
git push --set-upstream origin backport-4258-to-release-2.2
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release-2.2

Then, create a pull request where the base branch is release-2.2 and the compare/head branch is backport-4258-to-release-2.2.

jp-dark pushed a commit that referenced this pull request Dec 5, 2025
* Adding shape validation for add_matrix_to_collection

* Adding test for add_X_layer

* Add context to the validation function

* Schema validation optional default False

* PR fixes

* PR fixes vol 2

* Adding all versions in tests

* Adding full docstrings

* Add entry in HISTORY.md

* Minor fixes for PR

* Opening internal var dataframe in read mode when writing & text fix

* PR fixes - timestamp, closed property

* Add unit tests for previous versions

* PR comments

* PR comments

* Add warning instead of log msg

* Rebase with main

* Final misc

* Match argument to all tests

(cherry picked from commit 2d91da6)
jp-dark added a commit that referenced this pull request Dec 5, 2025
* Adding shape validation for add_matrix_to_collection

* Adding test for add_X_layer

* Add context to the validation function

* Schema validation optional default False

* PR fixes

* PR fixes vol 2

* Adding all versions in tests

* Adding full docstrings

* Add entry in HISTORY.md

* Minor fixes for PR

* Opening internal var dataframe in read mode when writing & text fix

* PR fixes - timestamp, closed property

* Add unit tests for previous versions

* PR comments

* PR comments

* Add warning instead of log msg

* Rebase with main

* Final misc

* Match argument to all tests

(cherry picked from commit 2d91da6)

Co-authored-by: Konstantinos Tsitsimpikos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants