Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow extra keywords in structured datatype validation #1901

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ def test_structured_datatype_validation(tmp_path):
data: [[1, 'a'], [2, 'b'], [3, 'c']]
datatype:
- name: a
description: a description
datatype: int8
- name: b
datatype: ['ascii', 8]
Expand All @@ -829,6 +830,7 @@ def test_structured_datatype_validation(tmp_path):
- name: a
datatype: int64
- name: b
title: a title
datatype: ['ascii', 8]
"""
buff = helpers.yaml_to_asdf(content)
Expand Down
9 changes: 9 additions & 0 deletions asdf/tags/core/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from asdf import util
from asdf._jsonschema import ValidationError

_STRUCTURED_DATATYPE_KEYS = {"name", "datatype", "byteorder", "shape"}

_datatype_names = {
"int8": "i1",
"int16": "i2",
Expand Down Expand Up @@ -533,6 +535,13 @@ def validate_datatype(validator, datatype, instance, schema):
msg = "Not an array"
raise ValidationError(msg)

# We are only concerned with some fields from the datatype
# object in the schema so if the schema datatype is structured
# copy the datatype and drop the irrelevant fields
# name datatype byteorder shape
if isinstance(datatype, list) and len(datatype) and isinstance(datatype[0], dict):
datatype = [{k: v for k, v in subitem.items() if k in _STRUCTURED_DATATYPE_KEYS} for subitem in datatype]

if datatype == in_datatype:
return

Expand Down
1 change: 1 addition & 0 deletions changes/1901.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow extra keywords in structured datatype validation.
Loading