Skip to content

Commit

Permalink
feat: allow numbers as uns values (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hegeman authored Mar 22, 2024
1 parent 016b7fe commit 71c090b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cellxgene_schema_cli/cellxgene_schema/validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import math
import numbers
import os
import re
from datetime import datetime
Expand Down Expand Up @@ -770,6 +771,7 @@ def _validate_uns_dict(self, uns_dict: dict) -> None:
self.errors.append(f"uns['{key}'] cannot be an empty value.")
elif (
value is not None
and not isinstance(value, numbers.Number)
and type(value) is not bool
and not (isinstance(value, (np.bool_, np.bool)))
and len(value) == 0
Expand Down
11 changes: 11 additions & 0 deletions cellxgene_schema_cli/tests/test_schema_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,17 @@ def test_uns_scipy_matrices_cannot_be_empty(self, validator_with_adata):
validator.validate_adata()
assert validator.errors == ["ERROR: uns['test'] cannot be an empty value."]

def test_uns_numbers_are_allowed(self, validator_with_adata):
validator = validator_with_adata

validator.adata.uns["numpy.int64"] = numpy.int64(10)
validator.adata.uns["int"] = 1
validator.adata.uns["int_zero"] = 0
validator.adata.uns["float"] = float(4)
validator.adata.uns["numpy.float32"] = numpy.float32(3)
validator.validate_adata()
assert validator.errors == []

def test_colors_happy_path_duplicates(self, validator_with_adata):
validator = validator_with_adata
validator.adata.uns["suspension_type_colors"] = numpy.array(["lightgrey", "lightgrey"])
Expand Down

0 comments on commit 71c090b

Please sign in to comment.