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

Validate Should Detect Incorrect NDArray DType #27

Closed
PaulHuwe opened this issue Aug 20, 2021 · 2 comments
Closed

Validate Should Detect Incorrect NDArray DType #27

PaulHuwe opened this issue Aug 20, 2021 · 2 comments

Comments

@PaulHuwe
Copy link
Collaborator

Validate should detect when the dtype of an ndarray object does not match the dtype specified in the schema.

@eslavich
Copy link
Contributor

Do you have a failing example? I tested dtype validation and saw the expected error:

import numpy as np
from roman_datamodels.datamodels import FlatRefModel
from roman_datamodels.testing import factories

flat_ref = factories.create_flat_ref(data=np.zeros((4096, 4096), dtype=np.uint64))
Flat = FlatRefModel(flat_ref)
ValidationError: Can not safely cast from 'uint64' to 'float32'

Failed validating 'datatype' in schema['properties']['data']:
    {'datatype': 'float32',
     'ndim': 2,
     'tag': 'tag:stsci.edu:asdf/core/ndarray-1.0.0',
     'title': 'Flat data array'}

On instance['data']:
    {'byteorder': 'little',
     'datatype': 'uint64',
     'shape': [4096, 4096],
     'source': 0}

@eslavich
Copy link
Contributor

@PaulHuwe and I discussed this on Slack, the problem lies with dtypes that are "compatible" as far as np.can_cast(np_in_datatype, np_datatype, 'safe') is concerned, but aren't exact matches. There's a schema feature that allows us to require an exact match on the datatype:

https://github.com/asdf-format/asdf-standard/blob/master/schemas/stsci.edu/asdf/asdf-schema-1.0.0.yaml#L41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants