diff --git a/src/hdmf/build/manager.py b/src/hdmf/build/manager.py index 448567ccc..3dce4281e 100644 --- a/src/hdmf/build/manager.py +++ b/src/hdmf/build/manager.py @@ -497,7 +497,7 @@ def load_namespaces(self, **kwargs): 'utf-8': str, 'ascii': bytes, 'bytes': bytes, - 'bool': bool, + 'bool': (bool, np.bool_), 'isodatetime': datetime, 'datetime': datetime } diff --git a/src/hdmf/spec/spec.py b/src/hdmf/spec/spec.py index 4af161c50..26bc4a905 100644 --- a/src/hdmf/spec/spec.py +++ b/src/hdmf/spec/spec.py @@ -32,7 +32,7 @@ class DtypeHelper: 'long': ["int64", "long"], 'utf': ["text", "utf", "utf8", "utf-8"], 'ascii': ["ascii", "bytes"], - 'bool': ["bool"], + 'bool': ["bool", "bool_"], 'int8': ["int8"], 'uint8': ["uint8"], 'uint16': ["uint16"], diff --git a/src/hdmf/utils.py b/src/hdmf/utils.py index b4d7297b8..b9230c4c9 100644 --- a/src/hdmf/utils.py +++ b/src/hdmf/utils.py @@ -10,7 +10,7 @@ __macros = { 'array_data': [np.ndarray, list, tuple, h5py.Dataset], - 'scalar_data': [str, int, float, bytes], + 'scalar_data': [str, int, float, bytes, bool], 'data': [] } diff --git a/tests/unit/utils_test/test_docval.py b/tests/unit/utils_test/test_docval.py index 3ee1174fa..de9308171 100644 --- a/tests/unit/utils_test/test_docval.py +++ b/tests/unit/utils_test/test_docval.py @@ -976,13 +976,13 @@ def test_macro(self): self.assertTrue(isinstance(get_docval_macro(), dict)) self.assertSetEqual(set(get_docval_macro().keys()), {'array_data', 'scalar_data', 'data'}) - self.assertTupleEqual(get_docval_macro('scalar_data'), (str, int, float, bytes)) + self.assertTupleEqual(get_docval_macro('scalar_data'), (str, int, float, bytes, bool)) @docval_macro('scalar_data') class Dummy1: pass - self.assertTupleEqual(get_docval_macro('scalar_data'), (str, int, float, bytes, Dummy1)) + self.assertTupleEqual(get_docval_macro('scalar_data'), (str, int, float, bytes, bool, Dummy1)) @docval_macro('dummy') class Dummy2: diff --git a/tests/unit/validator_tests/test_validate.py b/tests/unit/validator_tests/test_validate.py index 02406efab..b4d5aed6c 100644 --- a/tests/unit/validator_tests/test_validate.py +++ b/tests/unit/validator_tests/test_validate.py @@ -311,6 +311,16 @@ def test_bool_for_numeric(self): "Bar/data (my_bar/data): incorrect type - expected 'numeric', got 'bool'"} self.assertEqual(result_strings, expected_errors) + def test_np_bool_for_bool(self): + """Test that validator allows np.bool_ data where bool is specified.""" + self.set_up_spec('bool') + value = np.bool_(True) + bar_builder = GroupBuilder('my_bar', + attributes={'data_type': 'Bar', 'attr1': value}, + datasets=[DatasetBuilder('data', value)]) + results = self.vmap.validate(bar_builder) + self.assertEqual(len(results), 0) + class Test1DArrayValidation(TestCase):