Skip to content

Commit a4508c7

Browse files
committed
Add deprecation warnings
1 parent 861b572 commit a4508c7

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/stdatamodels/jwst/datamodels/tests/test_open.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,16 @@ def test_open_kwargs_fits(tmp_path):
290290
with pytest.raises(ValidationError):
291291
with datamodels.open(file_path, strict_validation=True) as model:
292292
model.validate()
293+
294+
295+
def test_memmap_deprecation(tmp_path):
296+
"""
297+
Test that the deprecation warning for memmap=True is raised.
298+
"""
299+
path = str(tmp_path / "test.fits")
300+
model = ImageModel((10, 10))
301+
model.save(path)
302+
303+
with pytest.warns(DeprecationWarning, match="Memory mapping is no longer supported"):
304+
with datamodels.open(path, memmap=True):
305+
pass

src/stdatamodels/jwst/datamodels/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def open(init=None, guess=True, **kwargs): # noqa: A001
6666
"""
6767
from . import model_base
6868

69+
if "memmap" in kwargs:
70+
warnings.warn(
71+
"Memory mapping is no longer supported; memmap is hard-coded to False "
72+
"and the keyword argument no longer has any effect.",
73+
DeprecationWarning,
74+
stacklevel=2,
75+
)
76+
kwargs.pop("memmap")
77+
6978
# Initialize variables used to select model class
7079

7180
hdulist = {}

src/stdatamodels/model_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def __init__(
133133
Additional keyword arguments passed to lower level functions. These arguments
134134
are generally file format-specific.
135135
"""
136+
if "memmap" in kwargs:
137+
warnings.warn(
138+
"Memory mapping is no longer supported; memmap is hard-coded to False "
139+
"and the keyword argument no longer has any effect.",
140+
DeprecationWarning,
141+
stacklevel=2,
142+
)
143+
kwargs.pop("memmap")
144+
136145
# Override value of validation parameters if not explicitly set.
137146
if pass_invalid_values is None:
138147
pass_invalid_values = get_envar_as_boolean("PASS_INVALID_VALUES", False)

tests/test_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,8 @@ def test_from_fits_deprecation():
403403
def test_from_asdf_deprecation():
404404
with pytest.warns(DeprecationWarning, match="from_asdf is deprecated"):
405405
DataModel.from_asdf({})
406+
407+
408+
def test_memmap_deprecation():
409+
with pytest.warns(DeprecationWarning, match="Memory mapping is no longer supported"):
410+
DataModel(memmap=True)

0 commit comments

Comments
 (0)