astropy / asdf-astropy

This is the extension library for ASDF to provide support for Astropy.
https://asdf-astropy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
15 stars 14 forks source link

Allow lazy loading of Quantity instances created during deserialization #190

Open braingram opened 1 year ago

braingram commented 1 year ago

Currently the Quantity converter calls _make_array before creating the Quantity: https://github.com/astropy/asdf-astropy/blob/0c502517a5cca9a6ce03150ad0c6472ae12a2e1f/asdf_astropy/converters/unit/quantity.py#L33

When the array is stored as an internal ASDF block this will force the block to be loaded at the time of deserialization.

Initial attempts to enable lazy loading by removing the above mentioned line do not prevent the ASDF block from being loaded possibly because NDArrayType is not a subclass of ndarray and astropy will attempt to iterate through the array during loading: https://github.com/astropy/astropy/blob/79dd50f61ef5e0a568dd42549319db38fefd0bc7/astropy/units/quantity.py#L495 triggering loading of the ASDF block.

WilliamJamieson commented 1 year ago

Whenever Quantity is updated to support the Python array API standard, then this will become trivial because Quantity will no longer subclass ndarray, instead it will satisfy the API's protocol.