New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added two optional arguments to Header.remove and removed AstropyDeprecationWarning #4445
Conversation
https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/test_header.py#L1386 |
This is why it's good to write tests first, and run the tests before committing. It'll catch things like syntax errors, of course, but will also make sure sure (assuming the test itself is written well) that your code does the right thing, etc. |
|
||
del self[self.index(keyword)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now that the original code went through self.index
too, so that's probably why you kept it that way. :) Yeah, it would be a slight enhancement for this to go directly through self._keyword_indices
instead.
Though it occurs to me now that since the keyword
variable here is user-input, it should also be "normalized" before being compared with the entries in self._keyword_indices
(this already happens in self.index which may be why I used it originally).
So before doing anything in this method run:
keyword = Card.normalize_keyword(keyword)
Users are sometimes inconsistent about how they write FITS keywords--so this puts them in a "normalized" form where they're all upper-case, etc.
Nitpicks aside, this is the right idea and on a good track. Thanks @Pratik151 |
@@ -221,21 +221,11 @@ def __delitem__(self, key): | |||
indices = self._rvkc_indices | |||
|
|||
if key not in indices: | |||
if _is_astropy_internal(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and another thing I meant to point out....
Now that this is removed, the _is_astropy_internal
function isn't used anywhere, so you can just remove this function entirely too (as well as the imports of inspect
and sys
since they aren't used anywhere in this module once _is_astropy_internal
is removed).
@embray Will update all things and also add tests. |
@embray Sorry for being late, I started to work on this today. When I try to delete keyword which is not present using
Should this behave like dictionary and throw I am able to work with this PR with some condition checking but just wanted to make sure behaviour of |
@Pratik151 |
@embray Does this look good? or I need to change something? |
As @saimn wrote if 'A' in self._keyword_indices:
del self[self._keyword_indices['A'][0]] Otherwise attempting to access |
del self[self._keyword_indices[keyword][0]] | ||
except KeyError: | ||
if not ignore_missing: | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now, I think I misled you by forgetting, myself, that keyword_indices is a defaultdict, and won't raise a KeyError
.
In this case adding the try/except overcomplicates things. Just change this to:
if keyword in self._keyword_indices:
del ...
if all:
...etc...
elif not ignore_missing:
raise KeyError(....)
Make the text for that last KeyError
the same as this one. You can see that the end result is the exact same logic, but vastly simplified.
@embray Thanks for review. Simplified the code :) |
Looks good. Now it just needs a changelog entry. Three really. Two for the new arguments under "New Features" and one under "API Changes" for the change in header keyword deletion. |
@embray Added changes to CHANGES.rst. Should I add more description in API changes? Travis CI build is failing because of some conflicts in packages.
|
The travis docs build failure is unrelated to this PR, the build should pass once restarted. |
@embray can you restart the build for this and review :) . Sorry for pinging you again. |
@Pratik151 - can you rebase this? It looks like there is a conflict |
@astrofrog I will do it in couple of days. I am out now and don't have access my machine here. |
@Pratik151 - Could you rebase please? |
addresses #4429
Does this look good?
I am looking into docs now and will change it soon.