Skip to content

Make ASDF extension robust to missing asdf-astropy#2268

Open
larrybradley wants to merge 1 commit intoastropy:mainfrom
larrybradley:asdf-astropy-optional
Open

Make ASDF extension robust to missing asdf-astropy#2268
larrybradley wants to merge 1 commit intoastropy:mainfrom
larrybradley:asdf-astropy-optional

Conversation

@larrybradley
Copy link
Copy Markdown
Member

This is a followup to #2211. Initial ASDF converters were added in #2211, but with asdf-astropy as an optional dependency. Previously, attempting to serialize a CircularAperture or AiryDiskPSF to ASDF without asdf-astropy installed raised an AsdfSerializationError with a long traceback.

This PR fixes that by always registering both converters. CircularApertureConverter works fully with only asdf. AiryDiskPSFConverter falls back to a plain asdf.extension.Converter base class when asdf-astropy is absent, and its to_yaml_tree/from_yaml_tree methods raise a clear ImportError pointing the user to pip install asdf-astropy instead of a deep traceback.

@larrybradley larrybradley added this to the 3.1.0 milestone May 1, 2026
@larrybradley larrybradley requested a review from nden May 1, 2026 18:06
@larrybradley
Copy link
Copy Markdown
Member Author

Pinging @braingram as a potential reviewer too.

@braingram
Copy link
Copy Markdown

This seems like a complicated distinction to make. Is there much benefit in supporting an environment that supports serializing some objects when asdf is installed and not asdf-astropy (which essentially only depends on asdf and astropy)? For example is it possible to construct a CircularAperture with quantities? Those wouldn't be supported without asdf-astropy and wouldn't trigger the custom error message added here.

If the goal is to provide a custom message if asdf is used but asdf-astropy is not installed perhaps it would be easier to register a extension that supports all photutils tags and photutils types (that have asdf support) and displays the message on read/write?

@larrybradley
Copy link
Copy Markdown
Member Author

@braingram Many thanks for the review! CircularAperture can't be constructed with Quantities, but SkyCircularAperture (which I assume will be coming) requires Quantities (and SkyCoord).

The goal was provide a custom/friendly error message. My solution also doesn't scale -- and @nden is adding more converters (to cover all aperture and psf models). sunpy also has asdf-astropy as an optional dependency. I'll take a look to see if they have added any custom error messages or anything similar. I might be overthinking this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants