Skip to content

Commit

Permalink
Only allow serializing default units.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Feb 21, 2024
1 parent 72ed676 commit 58272c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def load(rec, context)
import numpy as np
from matplotlib.colors import Colormap
from matplotlib import cm
import astropy.units as u
from astropy.units import UnitBase, Unit
from astropy.wcs import WCS
import shapely
Expand Down Expand Up @@ -624,7 +625,14 @@ def _load_slice(rec, context):

@saver(UnitBase)
def _save_unit_base(unit, context):
return dict(unit_base=unit.to_string())
unit_str = unit.to_string()
# Check that unit can be parsed back with default enabled systems
try:
with u.set_enabled_units([u.si, u.cgs, u.astrophys]):
_ = u.Unit(unit_str)
except ValueError:
raise GlueSerializeError(f"Serializing units of '{unit}' is not yet supported")

Check warning on line 634 in glue/core/state.py

View check run for this annotation

Codecov / codecov/patch

glue/core/state.py#L633-L634

Added lines #L633 - L634 were not covered by tests
return dict(unit_base=unit_str)


@loader(UnitBase)
Expand Down

0 comments on commit 58272c1

Please sign in to comment.