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

Support __asdf__ interface? #112

Closed
astrofrog opened this issue Apr 27, 2015 · 4 comments
Closed

Support __asdf__ interface? #112

astrofrog opened this issue Apr 27, 2015 · 4 comments

Comments

@astrofrog
Copy link
Contributor

While playing around with trying to store Astropy objects in ASDF (e.g. astropy/astropy#3733) I was wondering how we might best make it easy for developers to make their kinds of objects storable in ASDF. One option would be to check if objects have a __asdf__ method that if called will return a valid ASDF structure that can be included in a file? (with all the correct meta-data).

@mdboom
Copy link
Contributor

mdboom commented Apr 28, 2015

I had initially considered this, but the shortcoming is that it's only one-way -- you can only use this to store a custom object in ASDF. So you ultimately to have something "off the side" (i.e. not on objects) that can be used to unserialize the objects.

This is documented here: http://pyasdf.readthedocs.org/en/latest/pyasdf/extensions.html

While there's probably some room for improvement, I think it's superior to using a special member because it wraps the serialization/deserialization in a single class.

@mdboom mdboom closed this as completed Apr 28, 2015
@astrofrog
Copy link
Contributor Author

Ok, sounds good!

@embray
Copy link
Contributor

embray commented May 4, 2015

I think there's more that goes into storing arbitrary objects in ASDF too. For example you need support in the schema and the like. That could be declared in an object too, but I think in practice Mike's approach is better.

@mdboom
Copy link
Contributor

mdboom commented May 5, 2015

The other important point I forgot to mention is that doing things "off to the side" like this lets us handle objects we don't control, such as Numpy arrays. (i.e. we can support them in ASDF without submitting patches to Numpy).

embray pushed a commit to embray/pyasdf that referenced this issue Aug 21, 2015
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

3 participants