diff --git a/cellxgene_schema_cli/cellxgene_schema/validate.py b/cellxgene_schema_cli/cellxgene_schema/validate.py index 9bd6c475..041aecb7 100644 --- a/cellxgene_schema_cli/cellxgene_schema/validate.py +++ b/cellxgene_schema_cli/cellxgene_schema/validate.py @@ -1,5 +1,6 @@ import logging import math +import numbers import os import re from datetime import datetime @@ -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 diff --git a/cellxgene_schema_cli/tests/test_schema_compliance.py b/cellxgene_schema_cli/tests/test_schema_compliance.py index d2050664..a918f728 100644 --- a/cellxgene_schema_cli/tests/test_schema_compliance.py +++ b/cellxgene_schema_cli/tests/test_schema_compliance.py @@ -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"])