Skip to content

Commit

Permalink
DEPR: deprecate 'clobber' alias for overwrite keyword argument
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Apr 10, 2024
1 parent 9d32553 commit c27a775
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
35 changes: 11 additions & 24 deletions ccdproc/image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from astropy.table import Table, MaskedColumn
import astropy.io.fits as fits
from astropy.utils import minversion

import warnings
from astropy.utils.exceptions import AstropyUserWarning
Expand All @@ -24,8 +23,6 @@
__all__ = ['ImageFileCollection']
__doctest_skip__ = ['*']

_ASTROPY_LT_1_3 = not minversion("astropy", "1.3")


class ImageFileCollection:
"""
Expand Down Expand Up @@ -803,7 +800,6 @@ def _fits_files_in_directory(self, extensions=None,

def _generator(self, return_type,
save_with_name="", save_location='',
clobber=False,
overwrite=False,
do_not_scale_image_data=True,
return_fname=False,
Expand Down Expand Up @@ -839,10 +835,6 @@ def _generator(self, return_type,
If ``True``, overwrite input FITS files.
Default is ``False``.
clobber : bool, optional
Alias for ``overwrite``.
Default is ``False``.
do_not_scale_image_data : bool, optional
If ``True``, prevents fits from scaling images. Default is
``{default_scaling}``.
Expand Down Expand Up @@ -938,20 +930,9 @@ def _generator(self, return_type,

new_path = path.join(destination_dir, basename)

# I really should have called the option overwrite from
# the beginning. The hack below ensures old code works,
# at least...
if clobber or overwrite:
if _ASTROPY_LT_1_3:
nuke_existing = {'clobber': True}
else:
nuke_existing = {'overwrite': True}
else:
nuke_existing = {}

if return_type == 'ccd':
pass
elif (new_path != full_path) or nuke_existing:
elif (new_path != full_path) or overwrite:
with fits.open(full_path, **add_kwargs) as hdulist:
ext_index = hdulist.index_of(self.ext)
if return_type == 'hdu':
Expand All @@ -962,7 +943,7 @@ def _generator(self, return_type,
hdulist[ext_index].header = return_thing

try:
hdulist.writeto(new_path, **nuke_existing)
hdulist.writeto(new_path, overwrite=overwrite)
except IOError:
logger.error('error writing file %s', new_path)
raise
Expand Down Expand Up @@ -1002,9 +983,15 @@ def data(self, do_not_scale_image_data=False, **kwd):
name='image', default_scaling='False', return_type='numpy.ndarray')

def ccds(self, ccd_kwargs=None, **kwd):
if kwd.get('clobber') or kwd.get('overwrite'):
raise NotImplementedError(
"overwrite=True (or clobber=True) is not supported for CCDs.")
if (clobber := kwd.get('clobber')) is not None:
warnings.warn(
"The 'clobber' keyword argument is a deprecated alias for 'overwrite'",
category=DeprecationWarning,
stacklevel=2
)
kwd["overwrite"] = clobber
if kwd.get('overwrite'):
raise NotImplementedError("overwrite=True is not supported for CCDs.")
return self._generator('ccd', ccd_kwargs=ccd_kwargs, **kwd)
ccds.__doc__ = _generator.__doc__.format(
name='CCDData', default_scaling='True', return_type='astropy.nddata.CCDData')
2 changes: 1 addition & 1 deletion ccdproc/tests/test_image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def test_ccds_generator_does_not_support_overwrite(self, triage_setup):
ic = ImageFileCollection(triage_setup.test_dir)
with pytest.raises(NotImplementedError):
ic.ccds(overwrite=True)
with pytest.raises(NotImplementedError):
with pytest.deprecated_call(), pytest.raises(NotImplementedError):
ic.ccds(clobber=True)

def test_glob_matching(self, triage_setup):
Expand Down

0 comments on commit c27a775

Please sign in to comment.