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

NDArrayType attributes when reading from tree #1015

Closed
CagtayFabry opened this issue Aug 17, 2021 · 2 comments · Fixed by #1031
Closed

NDArrayType attributes when reading from tree #1015

CagtayFabry opened this issue Aug 17, 2021 · 2 comments · Fixed by #1031

Comments

@CagtayFabry
Copy link
Contributor

The NDArrayType is a bit different from other asdf types in that the from_tree returns an instance of the NDArrayType (instead of the mapped python types)

This also means that you can access the classattributes .name='core/ndarray' and .version='1.0.0' from any instance. From my understanding, these attributes are only used for generating the appropriate tag mapping for the asdf extension?

Unfortunately this can have unexpected results when using the loaded array with other libraries that check for these attributes on class creation, see here BAMWelDX/weldx#110

In the attributes are not needed on the instances returned by from_tree by asdf after creation, can they be set to None so that other code is less likely to pick them up? see CagtayFabry@603b016

@eslavich
Copy link
Contributor

From my understanding, these attributes are only used for generating the appropriate tag mapping for the asdf extension?

Yes, that's right. The instance of NDArrayType wraps np.ndarray, while the NDArrayType class methods implement the ExtensionType interface. I find this terribly confusing.

Ideally I think we'd just separate NDArrayType into two different classes, one for the np.ndarray wrapper and another for the ExtensionType implementation. I was planning to do that when switching the built-in types to the new converter API, but we can try to get it done earlier if it's causing problems for you.

@CagtayFabry
Copy link
Contributor Author

It's not really a pressing issue since it's rather easy to handle (once you know where to look)

maybe I'll open a PR with the small changes above and we can have a look if it breaks anything in the pipelines?

and totally, seperating the class with the new coverter should make the interfaces much easier to understand

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

Successfully merging a pull request may close this issue.

2 participants