Skip to content

Commit

Permalink
Merge branch 'dev' into improve_html_repr_of_data
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Oct 31, 2024
2 parents 495e626 + 06a62b9 commit 03c9f8f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NOTE: run `pre-commit autoupdate` to update hooks to latest version
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -18,7 +18,7 @@ repos:
# hooks:
# - id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
rev: v0.7.1
hooks:
- id: ruff
# - repo: https://github.com/econchick/interrogate
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Added support for expandable datasets of references for untyped and compound data types. @stephprince [#1188](https://github.com/hdmf-dev/hdmf/pull/1188)
- Improved html representation of data in `Containers` @h-mayorquin [#1100](https://github.com/hdmf-dev/hdmf/pull/1100)

### Bug fixes
- Fixed inaccurate error message when validating reference data types. @stephprince [#1199](https://github.com/hdmf-dev/hdmf/pull/1199)

## HDMF 3.14.5 (October 6, 2024)

### Enhancements
Expand Down
6 changes: 5 additions & 1 deletion src/hdmf/validate/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ def validate(self, **kwargs):
try:
dtype, string_format = get_type(data, builder.dtype)
if not check_type(self.spec.dtype, dtype, string_format):
ret.append(DtypeError(self.get_spec_loc(self.spec), self.spec.dtype, dtype,
if isinstance(self.spec.dtype, RefSpec):
expected = f'{self.spec.dtype.reftype} reference'
else:
expected = self.spec.dtype
ret.append(DtypeError(self.get_spec_loc(self.spec), expected, dtype,
location=self.get_builder_loc(builder)))
except EmptyArrayError:
# do not validate dtype of empty array. HDMF does not yet set dtype when writing a list/tuple
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/validator_tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,38 @@ def test_scalar_compound_dtype(self):
results = self.vmap.validate(bar_builder)
self.assertEqual(len(results), 0)

class TestReferenceValidation(ValidatorTestBase):
def getSpecs(self):
qux_spec = DatasetSpec(
doc='a simple scalar dataset',
data_type_def='Qux',
dtype='int',
shape=None
)
bar_spec = GroupSpec('A test group specification with a reference dataset',
data_type_def='Bar',
datasets=[DatasetSpec('an example dataset',
dtype=RefSpec('Qux', reftype='object'),
name='data',
shape=(None, ))],
attributes=[AttributeSpec('attr1',
'an example attribute',
dtype=RefSpec('Qux', reftype='object'),
shape=(None, ))])
return (qux_spec, bar_spec)

def test_invalid_reference(self):
"""Test that validator does not allow another data type where a reference is specified."""
value = np.array([1.0, 2.0, 3.0])
bar_builder = GroupBuilder('my_bar',
attributes={'data_type': 'Bar', 'attr1': value},
datasets=[DatasetBuilder('data', value)])
results = self.vmap.validate(bar_builder)
result_strings = set([str(s) for s in results])
expected_errors = {"Bar/attr1 (my_bar.attr1): incorrect type - expected 'object reference', got 'float64'",
"Bar/data (my_bar/data): incorrect type - expected 'object reference', got 'float64'"}
self.assertEqual(result_strings, expected_errors)

class Test1DArrayValidation(TestCase):

def set_up_spec(self, dtype):
Expand Down

0 comments on commit 03c9f8f

Please sign in to comment.