Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Add type checks to obsm, obsp, varm and varp early in ingestion #2131

Merged
merged 3 commits into from
Feb 13, 2024

Conversation

XanthosXanthopoulos
Copy link
Collaborator

Issue and/or context:
closes #2118

Changes:
Adds explicit type checks to from_anndata for obsm, obsp, varm and varp before the actual ingestion start to catch the case where a DataFrame is passed.

Notes for Reviewer:

@XanthosXanthopoulos XanthosXanthopoulos changed the title Add type checks to obsm, obsp, varm and varp early in ingestion [python] Add type checks to obsm, obsp, varm and varp early in ingestion Feb 13, 2024
Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Merging #2131 (1bf36de) into main (fae2ac1) will increase coverage by 12.73%.
Report is 4 commits behind head on main.
The diff coverage is 61.53%.

❗ Current head 1bf36de differs from pull request most recent head ac10e71. Consider uploading reports for the commit ac10e71 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2131       +/-   ##
===========================================
+ Coverage   78.52%   91.25%   +12.73%     
===========================================
  Files         136       35      -101     
  Lines       10759     3807     -6952     
  Branches      209        0      -209     
===========================================
- Hits         8448     3474     -4974     
+ Misses       2211      333     -1878     
+ Partials      100        0      -100     
Flag Coverage Δ
libtiledbsoma ?
python 91.25% <61.53%> (+0.51%) ⬆️
r ?

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

Components Coverage Δ
python_api 91.25% <61.53%> (+0.51%) ⬆️
libtiledbsoma ∅ <ø> (∅)

Copy link
Member

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

@XanthosXanthopoulos thanks for working on this! :)

Let's also add a unit-test case

  • In apis/python/tests/test_basic_anndata_io.py
  • You can get adata
  • Make a bdata with bdata = ad.AnnData(X=adata.X, obs=adata.obs, var=adata.var, obsm={"testing": adata.obs}) -- this will result in a dataframe being in an obsm slot
  • Wrap a from_anndata call in with pytest.raises(TypeError)
  • Assert the destination SOMA URI doesn't exist at all (i.e. there was no partial write)

for key in anndata.obsm.keys():
if not isinstance(anndata.obsm[key], get_args(Matrix)):
raise TypeError(
f"Obsm value at {key} in not of type {list(cl.__name__ for cl in get_args(Matrix))}"
Copy link
Member

Choose a reason for hiding this comment

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

Users will expect obsm not Obsm -- same for the other three

Copy link
Member

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

🚢 Thanks @XanthosXanthopoulos !!! 🚢

@johnkerl
Copy link
Member

johnkerl commented Feb 13, 2024

@XanthosXanthopoulos please feel free to self-merge once CI is green

@XanthosXanthopoulos XanthosXanthopoulos merged commit ef6cb19 into main Feb 13, 2024
1 check passed
@XanthosXanthopoulos XanthosXanthopoulos deleted the xan/early-error-dataframe-on-ingest branch February 13, 2024 23:35
Copy link

The backport to release-1.7 failed:

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

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-1.7 release-1.7
# Navigate to the new working tree
cd .worktrees/backport-release-1.7
# Create a new branch
git switch --create backport-2131-to-release-1.7
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 ef6cb19ef8dd159db08d602acdb68409da51cdee
# Push it to GitHub
git push --set-upstream origin backport-2131-to-release-1.7
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release-1.7

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

johnkerl pushed a commit that referenced this pull request Feb 14, 2024
…ame-on-ingest

[python] Add type checks to `obsm`, `obsp`, `varm` and `varp` early in ingestion
johnkerl pushed a commit that referenced this pull request Feb 14, 2024
…ame-on-ingest

[python] Add type checks to `obsm`, `obsp`, `varm` and `varp` early in ingestion
johnkerl added a commit that referenced this pull request Feb 14, 2024
…arm` and `varp` early in ingestion (#2138)

* Merge pull request #2131 from single-cell-data/xan/early-error-dataframe-on-ingest

[python] Add type checks to `obsm`, `obsp`, `varm` and `varp` early in ingestion

* Merge pull request #2131 from single-cell-data/xan/early-error-dataframe-on-ingest

[python] Add type checks to `obsm`, `obsp`, `varm` and `varp` early in ingestion

* complete merge

---------

Co-authored-by: XanthosXanthopoulos <[email protected]>
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.

[python] Early error for dataframe objects presented as obsm etc. on ingest
2 participants