Repository navigation
Replace clobber parameter with overwrite - #5171
Conversation
|
A note on the implementation: A note on the unit tests: |
|
I'm not really sure if it may be a problem that you added the Also catching On the other hand I'm not really sure if using Thank you for this thorough PR. I'll have a closer look in the next days. |
| If `True`, overwrite the output file if exists. | ||
| The use of clobber is deprecated; use overwrite instead. | ||
|
|
||
| overwrite : bool, optional |
There was a problem hiding this comment.
Sphinx has a versionadded and deprecated-directive. I haven't seen it regularly used but I think it could make sense here.
For clobber this would be something like
.. deprecated:: 1.3
Use the ``overwrite`` argument instead.
and for overwrite: .. versionadded:: 1.3
|
@MSeifert04 Thanks for catching that; I had totally overlooked the fact that keyword arguments might be used as positional arguments in existing code. I had simply placed I'll have a look at the Sphinx directives. |
|
+1 for adding overwrite, but I think that deprecating clobber is very annoying for a very little gain. clobber must be used in a lot of code, and I fear people will get warnings for a long time before having a clobber-free code base. This is the kind of things that will bother people. So they will filter warnings, and all other |
|
|
||
| - FITS writers now accept an ``overwrite`` argument. If ``clobber`` | ||
| is used, an ``AstropyDeprecationWarning`` is issued. If both are | ||
| used, a ``ValueError`` is raised. |
There was a problem hiding this comment.
Need to append PR number here. See other entries for example.
|
Replacing if clobber in kwargs:
issue_deprecation_warning
overwrite = clobberOr if you want to be stricter, maybe something like (but I think the former is nicer to people who already use if clobber in kwargs:
issue_deprecation_warning
if overwrite is not None:
raise ValueError('You have to explicitly set overwrite=None to use clobber')
overwrite = clobber |
| clobber : bool, optional | ||
| If `True`, and if filename already exists, it will overwrite | ||
| the file. Default is `False`. | ||
| If `True`, overwrite the output file if exists. |
There was a problem hiding this comment.
If we move clobber into kwargs, this text can go into .. note:: section in the docstring. The code should also issue an explicit DeprecationWarning with this text.
We should at least keep one test that uses the old |
|
I see a few different opinions and suggestions above, and I'm not sure how now to proceed. saimn makes the correct argument that There is also the suggestion of moving I'm not really sure how much checking there should be to see whether both |
|
I propose:
Feel free to discuss further. Those are just my personal thoughts. |
|
I agree with @pllim but I want to propose another point:
|
|
@pllim - I think the 2nd part of your point 2 is not backward compatibility, but a possibility to cause a big headache when the actual removal of Currently one gets a big So I would suggest to raise the |
|
Another way but be using a decorator to catch the parameters passed to the functions (this would work best at the high-level-functions) and resolve the conflicts before it is actually executed. Something (very roughly) like this: |
|
@bsipocz , whatever is fine. I'll let the main package maintainer decide which idea to adopt. |
|
I've now implemented the approach suggested by @MSeifert04 (thanks!), using a decorator. I made the decorator slightly more generic: it takes two arguments, the old and new keyword. See the diff for astropy.io.fits.util in this PR for the current implementation. Documentation-wise, I've left .. versionchanged: 1.3
overwrite replaces the clobber keyword. Clobber is deprecated.An example in the Python or numpy documentation would be good to use, but I haven't found one for this particular situation. |
astrofrog
left a comment
There was a problem hiding this comment.
👍 from me and it would be great to get this in 1.3. Just a couple of minor comments related to the changelog
|
|
||
| - FITS writers now accept an ``overwrite`` argument. If ``clobber`` | ||
| is used, an ``AstropyDeprecationWarning`` is issued. If both are | ||
| used, a ``TypeError`` is raised. [#5171] |
There was a problem hiding this comment.
I would rephrase this to say that 'The clobber argument in FITS writers has been renamed to overwrite' (then leave the bit about deprecation).
| is used, an ``AstropyDeprecationWarning`` is issued. If both are | ||
| used, a ``TypeError`` is raised. [#5171] | ||
|
|
||
| This change affects the following functions and methods: |
There was a problem hiding this comment.
Can you make the changelog entry into a single paragraph?
|
|
||
| - ``astropy.vo`` | ||
|
|
||
| - ``VOSDatabase.to_json()`` now accepts an ``overwrite`` argument. |
There was a problem hiding this comment.
As above - if the argument has been renamed, make that clearer (at the moment it sounds like a new option has been added.
``overwrite`` can now be used instead of ``clobber``. The ``clobber`` parameter is deprecated, and an AstropyDeprecationWarning will be issued if it is used instead of ``overwrite``. If both happen to be used, a TypeError is raised.
Follows from the discussion in #5492.
Also provides docstring links to the related methods.
Also fixes or reverts a few minor docstring irregularities introduced earlier.
|
It is approved, so merging. Thanks, @evertrol and @MSeifert04 ! p.s. "I am in fits and clobbered by trying to clobber a FITS file" does not sound that good by replacing "clobber" with "overwrite". |
|
👍 from me too (if a little late 😉 ) |
astropy has deprecated the `clobber` keyword from `astropy.io.fits` `writeto` method in favor of `overwrite` in version 2.0 cf. astropy/astropy#5171 Since version 5.1 (end of May 2022), it was finally removed.
astropy has deprecated the `clobber` keyword from `astropy.io.fits` `writeto` method in favor of `overwrite` in version 2.0 cf. astropy/astropy#5171 Since version 5.1 (end of May 2022), it was finally removed.
overwritecan now be used instead ofclobber. Theclobberparameter is deprecated, and an AstropyDeprecationWarning will be
issued if it is used instead of
overwrite. If both happen to beused, a ValueError is raised.