Skip to content

Commit

Permalink
avoid an extra validation on __init__ (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro authored Nov 18, 2024
2 parents 56fdcfd + 66d8d0a commit cbe5d1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/356.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid unnecessary validation on Model.__init__.
11 changes: 10 additions & 1 deletion src/stdatamodels/jwst/datamodels/tests/test_multislit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numpy.testing import assert_array_equal
import pytest

from stdatamodels.jwst.datamodels import MultiSlitModel, ImageModel
from stdatamodels.jwst.datamodels import MultiSlitModel, ImageModel, SlitModel


def test_multislit_model():
Expand Down Expand Up @@ -155,3 +155,12 @@ def test_copy_multislit():

assert model1.slits[0].data[330, 330] == 1
assert output.slits[0].data[330, 330] == -1


def test_slit_from_multislit():
model = MultiSlitModel()
slit = SlitModel()
# access int_times so it's created
slit.int_times = slit.int_times
model.slits.append(slit)
slit = SlitModel(model.slits[0].instance)
5 changes: 5 additions & 0 deletions src/stdatamodels/model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ def open_asdf(init=None,
ignore_unrecognized_tag=ignore_unrecognized_tag,
**kwargs)

elif isinstance(init, dict):
asdffile = AsdfFile(None,
ignore_unrecognized_tag=ignore_unrecognized_tag
)
asdffile._tree = init
else:
asdffile = AsdfFile(init,
ignore_unrecognized_tag=ignore_unrecognized_tag
Expand Down

0 comments on commit cbe5d1f

Please sign in to comment.