-
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
feat: fix X_{suffix} validation and add test coverage #635
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1258,6 +1258,49 @@ def test_obsm_values_ara_numpy(self): | |
], | ||
) | ||
|
||
def test_obsm_values_infinity(self): | ||
""" | ||
values in obsm cannot have any infinity values | ||
""" | ||
self.validator.adata.obsm["X_umap"][0:100, 1] = numpy.inf | ||
self.validator.validate_adata() | ||
self.assertEqual( | ||
self.validator.errors, | ||
["ERROR: adata.obsm['X_umap'] contains positive infinity or negative infinity values."], | ||
) | ||
|
||
def test_obsm_values_str(self): | ||
""" | ||
values in obsm must be numerical types, strings are not valid | ||
""" | ||
all_string = numpy.full(self.validator.adata.obsm["X_umap"].shape, "test") | ||
self.validator.adata.obsm["X_umap"] = all_string | ||
self.validator.validate_adata() | ||
self.assertEqual( | ||
self.validator.errors, | ||
["ERROR: adata.obsm['X_umap'] has an invalid data type. It should be float, integer, or unsigned " | ||
"integer of any precision (8, 16, 32, or 64 bits)."], | ||
) | ||
|
||
def test_obsm_values_nan(self): | ||
""" | ||
values in obsm cannot all be NaN | ||
""" | ||
|
||
# It's okay if only one value is NaN | ||
self.validator.adata.obsm["X_umap"][0:100, 1] = numpy.nan | ||
self.validator.validate_adata() | ||
self.assertEqual(self.validator.errors, []) | ||
|
||
# It's not okay if all values are NaN | ||
all_nan = numpy.full(self.validator.adata.obsm["X_umap"].shape, numpy.nan) | ||
self.validator.adata.obsm["X_umap"] = all_nan | ||
self.validator.validate_adata() | ||
self.assertEqual( | ||
self.validator.errors, | ||
["ERROR: adata.obsm['X_umap'] contains all NaN values."], | ||
) | ||
|
||
def test_obsm_values_at_least_one_X(self): | ||
""" | ||
At least one key for the embedding MUST be prefixed with "X_" | ||
|
@@ -1272,6 +1315,28 @@ def test_obsm_values_at_least_one_X(self): | |
["ERROR: At least one embedding in 'obsm' has to have a " "key with an 'X_' prefix."], | ||
) | ||
|
||
def test_obsm_suffix_name_valid(self): | ||
""" | ||
Suffix after X_ must be at least 1 character long | ||
""" | ||
self.validator.adata.obsm["X_"] = self.validator.adata.obsm["X_umap"] | ||
self.validator.validate_adata() | ||
self.assertEqual( | ||
self.validator.errors, | ||
["ERROR: Embedding key in 'adata.obsm' X_ must have a suffix at least one character long."], | ||
) | ||
|
||
def test_obsm_key_name_valid(self): | ||
""" | ||
Embedding keys with whitespace are not valid | ||
""" | ||
self.validator.adata.obsm["X_ umap"] = self.validator.adata.obsm["X_umap"] | ||
self.validator.validate_adata() | ||
self.assertEqual( | ||
self.validator.errors, | ||
["ERROR: Embedding key X_ umap has whitespace in it, please remove it."], | ||
) | ||
|
||
def test_obsm_shape(self): | ||
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. can you add a test for the other condition on this if conditional? i.e. must have same number of rows as X 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. i updated for the case where the number of rows is not the same as the number of cells. it actually seems to fail when setting the key, not when running the validation. but the test should reflect that |
||
""" | ||
Curators MUST annotate one or more two-dimensional (m >= 2) embeddings | ||
|
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.
i think any keys that have whitespace in them should be invalid, regardless of whether it's an
X_{suffix}
key