Skip to content

Commit 0d4fc48

Browse files
committed
allow extra keywords in structured datatype validation
1 parent d70ac0f commit 0d4fc48

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

asdf/_tests/tags/core/tests/test_ndarray.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ def test_structured_datatype_validation(tmp_path):
812812
data: [[1, 'a'], [2, 'b'], [3, 'c']]
813813
datatype:
814814
- name: a
815+
description: a description
815816
datatype: int8
816817
- name: b
817818
datatype: ['ascii', 8]
@@ -829,6 +830,7 @@ def test_structured_datatype_validation(tmp_path):
829830
- name: a
830831
datatype: int64
831832
- name: b
833+
title: a title
832834
datatype: ['ascii', 8]
833835
"""
834836
buff = helpers.yaml_to_asdf(content)

asdf/tags/core/ndarray.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from asdf import util
88
from asdf._jsonschema import ValidationError
99

10+
_STRUCTURED_DATATYPE_KEYS = {"name", "datatype", "byteorder", "shape"}
11+
1012
_datatype_names = {
1113
"int8": "i1",
1214
"int16": "i2",
@@ -533,6 +535,13 @@ def validate_datatype(validator, datatype, instance, schema):
533535
msg = "Not an array"
534536
raise ValidationError(msg)
535537

538+
# We are only concerned with some fields from the datatype
539+
# object in the schema so if the schema datatype is structured
540+
# copy the datatype and drop the irrelevant fields
541+
# name datatype byteorder shape
542+
if isinstance(datatype, list) and len(datatype) and isinstance(datatype[0], dict):
543+
datatype = [{k: v for k, v in subitem.items() if k in _STRUCTURED_DATATYPE_KEYS} for subitem in datatype]
544+
536545
if datatype == in_datatype:
537546
return
538547

0 commit comments

Comments
 (0)