From 0c1b64481e5cfc51da4b80eb417e8d87a7fd8875 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 4 Nov 2024 09:26:00 -0500 Subject: [PATCH 1/2] avoid an extra validation on __init__ --- .../jwst/datamodels/tests/test_multislit.py | 11 ++++++++++- src/stdatamodels/model_base.py | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/stdatamodels/jwst/datamodels/tests/test_multislit.py b/src/stdatamodels/jwst/datamodels/tests/test_multislit.py index 27b2c65d..8fce6821 100644 --- a/src/stdatamodels/jwst/datamodels/tests/test_multislit.py +++ b/src/stdatamodels/jwst/datamodels/tests/test_multislit.py @@ -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(): @@ -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) diff --git a/src/stdatamodels/model_base.py b/src/stdatamodels/model_base.py index a231a7d9..9042607d 100644 --- a/src/stdatamodels/model_base.py +++ b/src/stdatamodels/model_base.py @@ -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 From 66d8d0accf6fae234868413819e72124c41ff8d8 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 4 Nov 2024 09:33:20 -0500 Subject: [PATCH 2/2] add changelog --- changes/356.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/356.bugfix.rst diff --git a/changes/356.bugfix.rst b/changes/356.bugfix.rst new file mode 100644 index 00000000..faf9cfc0 --- /dev/null +++ b/changes/356.bugfix.rst @@ -0,0 +1 @@ +Avoid unnecessary validation on Model.__init__.