Repository: astropy/ccdproc
Pull request #823 (2024-04-10 07:36:22)

DEPR: deprecate 'clobber' alias for overwrite keyword argument
While testing the package, I stumbled upon a `_ASTROPY_LT_1_3` constant so I pulled the thread.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/astropy/ccdproc/pull/823?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 97.62%. Comparing base [(`b962f56`)](https://app.codecov.io/gh/astropy/ccdproc/commit/b962f564dd9c6ef37b14c8dabe859d38ca45d495?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) to head [(`af5d0e9`)](https://app.codecov.io/gh/astropy/ccdproc/pull/823?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).
> Report is 6 commits behind head on main.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #823      +/-   ##
==========================================
+ Coverage   97.55%   97.62%   +0.06%     
==========================================
  Files           9        9              
  Lines        1392     1388       -4     
==========================================
- Hits         1358     1355       -3     
+ Misses         34       33       -1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/astropy/ccdproc/pull/823?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).


Patch:
diff --git a/ccdproc/image_collection.py b/ccdproc/image_collection.py
index b6e17c0..8482090 100644
--- a/ccdproc/image_collection.py
+++ b/ccdproc/image_collection.py
@@ -12,7 +12,6 @@ import numpy.ma as ma
 
 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
@@ -24,8 +23,6 @@ logger = logging.getLogger(__name__)
 __all__ = ['ImageFileCollection']
 __doctest_skip__ = ['*']
 
-_ASTROPY_LT_1_3 = not minversion("astropy", "1.3")
-
 
 class ImageFileCollection:
     """
@@ -803,7 +800,6 @@ class ImageFileCollection:
 
     def _generator(self, return_type,
                    save_with_name="", save_location='',
-                   clobber=False,
                    overwrite=False,
                    do_not_scale_image_data=True,
                    return_fname=False,
@@ -839,10 +835,6 @@ class ImageFileCollection:
             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}``.
@@ -938,20 +930,9 @@ class ImageFileCollection:
 
             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':
@@ -962,7 +943,7 @@ class ImageFileCollection:
                         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
@@ -1002,9 +983,15 @@ class ImageFileCollection:
         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')


Test patch:
diff --git a/ccdproc/tests/test_image_collection.py b/ccdproc/tests/test_image_collection.py
index ee381ac..16abb82 100644
--- a/ccdproc/tests/test_image_collection.py
+++ b/ccdproc/tests/test_image_collection.py
@@ -755,7 +755,7 @@ class TestImageFileCollection:
         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):