-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix(schema 5.1.0): throw error if obsm is not type np.ndarray #859
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9af6bb1
throw error if obsm is not type np.ndarray
Bento007 78ee360
update tests
Bento007 a47bb5b
Merge branch 'main' into tsmith/857-obsm
Bento007 cb8e33e
fix tests
Bento007 70934d1
fix tests
Bento007 4e920ec
fix tests
Bento007 1a9ef99
fix tests
Bento007 aa58d26
fix tests
Bento007 862275f
Merge branch 'main' into tsmith/857-obsm
nayib-jose-gloria bdaa204
fix tests
nayib-jose-gloria 1070f0f
raise error if ndarray is incorrect shape in obsm
Bento007 08c3efc
add check for other embedding types
Bento007 3fc71a8
fix tests
Bento007 8bd86b5
undo random formatting changes
Bento007 e238093
Merge branch 'main' into tsmith/857-obsm
nayib-jose-gloria d8a8f2a
remove string check
Bento007 db518a3
improve error message
Bento007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -999,10 +999,14 @@ def _validate_obsm(self): | |
|
||
obsm_with_x_prefix = 0 | ||
for key, value in self.adata.obsm.items(): | ||
if not isinstance(key, str): | ||
# no validation on none string OBSM key types. | ||
continue | ||
issue_list = self.errors | ||
|
||
regex_pattern = r"^[a-zA-Z][a-zA-Z0-9_.-]*$" | ||
|
||
unknown_key = False # an unknown key does not match 'spatial' or 'X_{suffix}' | ||
if key.startswith("X_"): | ||
obsm_with_x_prefix += 1 | ||
if key.lower() == "x_spatial": | ||
|
@@ -1021,19 +1025,35 @@ def _validate_obsm(self): | |
f"not be available in Explorer" | ||
) | ||
issue_list = self.warnings | ||
unknown_key = True | ||
|
||
if not isinstance(value, np.ndarray): | ||
issue_list.append( | ||
self.errors.append( | ||
f"All embeddings have to be of 'numpy.ndarray' type, " f"'adata.obsm['{key}']' is {type(value)}')." | ||
) | ||
# Skip over the subsequent checks that require the value to be an array | ||
continue | ||
|
||
if len(value.shape) < 2 or value.shape[0] != self.adata.n_obs or value.shape[1] < 2: | ||
issue_list.append( | ||
f"All embeddings must have as many rows as cells, and at least two columns." | ||
f" 'adata.obsm['{key}']' has shape of '{value.shape}'." | ||
if len(value.shape) < 2: | ||
self.errors.append( | ||
f"All embeddings must at least two dimensions. 'adata.obsm['{key}']' has a shape length of '{len(value.shape)}'." | ||
) | ||
else: | ||
if value.shape[0] != self.adata.n_obs: | ||
self.errors.append( | ||
f"All embeddings must have as many rows as cells. 'adata.obsm['{key}']' has rows='{value.shape[0]}'." | ||
) | ||
|
||
if unknown_key and value.shape[1] < 1: | ||
self.errors.append( | ||
f"All other embeddings must have at least one column. 'adata.obsm['{key}']' has columns='{value.shape[1]}'." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: in this context, I don't think the curator reading would know what "other embeddings" mean. Maybe "any embeddings not specified in the schema reference"? |
||
) | ||
|
||
if not unknown_key and value.shape[1] < 2: | ||
self.errors.append( | ||
f"All 'X_' and 'spatial' embeddings must have at least two columns. 'adata.obsm['{key}']' has columns='{value.shape[1]}'." | ||
) | ||
|
||
if not (np.issubdtype(value.dtype, np.integer) or np.issubdtype(value.dtype, np.floating)): | ||
issue_list.append( | ||
f"adata.obsm['{key}'] has an invalid data type. It should be " | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: nvm previous statment was incorrect