-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Rename Fits
class in units.format
to FITS
#16455
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
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.
Thanks, this is great! I only have a suggestion for the changelog message - I think we should stress this was a private class. Indeed, arguably no changelog entry is needed, but we might as well be nice and have one.
docs/changes/units/16455.api.rst
Outdated
@@ -0,0 +1,2 @@ | |||
The ``format.Fits`` formatter class has been renamed to ``format.FITS``. |
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'd suggest:
The private ``astropy.units.format.Fits`` formatter class has been renamed to ``format.FITS``.
The old name is deprecated. Note that this does not affect regular user visible behaviour:
the formatters are selected indirectly via their lower-case name (in this case ``format="fits"``).
This change should have no effect except for those who may have subclassed the formatter.
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 expanded the change log entry, but not quite how you suggested. Mentioning format="fits"
seems to assume the use of the to_string()
method, but the formats can also be used in an f-string (e.g. f"{q:fits}"
), in which case there is no explicit format
argument.
Making the class name uppercase ensures it consistent with the CDS and OGIP unit formatter classes. The renaming should not impact users because the formatter classes are not meant to be imported directly.
f1737f4
to
086ccac
Compare
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 may have preferred for the changelog to mention explicitly that this class was a private one - it is not exposed under astropy.units
, but don't want to let the perfect be the enemy of good enough - so let's get this in! Thanks!
The unit formatter classes are a bit strange because they are not available from the |
Yes, that's a good point; definitely good then to have the changelog entry! (and your careful deprecation message) |
Are you sure we should do this? It broke specutils via gwcs, see https://github.com/astropy/specutils/actions/runs/9183362928/job/25253934562
|
Looks simple enough to address downstream. I'll open a PR later today unless anyone beats me to it :) |
OK thanks. I opened spacetelescope/gwcs#499 |
The |
I will just mention here that |
Description
Many unit formatter classes are named exactly (i.e. including capitalization) like the standard that they implement (e.g.
OGIP
orVOUnit
), but the class implementing FITS unit formatting is calledFits
instead ofFITS
. This is proving to be very inconvenient in #16445, which is reducing code duplication in theunits.format.Generic
subclasses by replacing some of their individual methods with common implementations inGeneric
. In particular, if the_validate_unit()
class method raises an error or a warning then the message should refer to the relevant unit standard, but usingcls.__name__
is not suitable becauseFits
has the wrong capitalization andcls.__name__.upper()
would ruin the capitalization ofVOUnit
. This pull request will therefore simplify #16445, but it is better to have separate pull requests for API changes and user-invisible refactoring.The renaming should have a very low impact for users because the unit formatter classes are not meant to be imported or used directly anyways.