You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dump and load (and the related dumps and loads) is the (perhaps informal) standard for serialization/deserialization in python. This API is supported by:
pickle
json
yaml (doesn't support dumps and loads)
toml
I propose that we add support for this API at the top level module to align asdf with other serialization packages in python.
This will have the added benefit of simplifying test code and examples.
asdf.dump example
For example writing a dict/tree to a file at the moment can be done with:
asdf.AsdfFile({"foo": 1}).write_to("foo.asdf")
this could be replaced with:
asdf.dump({"foo": 1}, "foo.asdf")
Non-lazy asdf.load
For load I propose that we set the default for lazy_load to False as it would otherwise cause issues for array data:
# assuming "foo.asdf" has an array at "arr"withasdf.open("foo.asdf") asaf:
tree=af.treetree["arr"][:] # results in an exception because the file is closed
So load could by used as follows:
tree=asdf.load("foo.asdf")
tree["arr"][:] # access to array data here results in no exception because it was not lazy loaded
Supported "file" argument
To detail a few supported options I suggest that we allow asdf.load and asdf.dump to handle:
strings as filenames
Paths as filenames
file-like objects
fsspec file objects (to support http, s3, etc)
Additional arguments
We will also want to consider how to handle additional keyword arguments as both asdf.open and AsdfFile (and AsdfFile.write_to) support a number of useful options that we can map to asdf.load and asdf.dump.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
dumpandload(and the relateddumpsandloads) is the (perhaps informal) standard for serialization/deserialization in python. This API is supported by:dumpsandloads)I propose that we add support for this API at the top level module to align asdf with other serialization packages in python.
This will have the added benefit of simplifying test code and examples.
asdf.dumpexampleFor example writing a dict/tree to a file at the moment can be done with:
this could be replaced with:
Non-lazy
asdf.loadFor
loadI propose that we set the default forlazy_loadtoFalseas it would otherwise cause issues for array data:So
loadcould by used as follows:Supported "file" argument
To detail a few supported options I suggest that we allow
asdf.loadandasdf.dumpto handle:Additional arguments
We will also want to consider how to handle additional keyword arguments as both
asdf.openandAsdfFile(andAsdfFile.write_to) support a number of useful options that we can map toasdf.loadandasdf.dump.All reactions