-
-
Notifications
You must be signed in to change notification settings - Fork 132
Handle new PhysicalType class in spectrum_from_column_mapping
#833
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
Changes from 3 commits
f838862
b8c7a25
60bb7fb
fcf624b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -522,14 +522,14 @@ def test_tabular_fits_writer(tmpdir, spectral_axis): | |
| spectrum.write(tmpfile, format='tabular-fits') | ||
| spectrum.write(tmpfile, format='tabular-fits', overwrite=True) | ||
|
|
||
| cmap = {spectral_axis: ('spectral_axis', wlu[spectral_axis]), | ||
| cmap = {spectral_axis: ('spectral_axis', 'micron'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed? It seems to defeat the purpose of the parameterized test.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 'flux': ('flux', 'erg / (s cm**2 AA)'), | ||
| 'uncertainty': ('uncertainty', None)} | ||
|
|
||
| # Read it back again and check against the original | ||
| spec = Spectrum1D.read(tmpfile, format='tabular-fits', column_mapping=cmap) | ||
| assert spec.flux.unit == u.Unit('erg / (s cm**2 AA)') | ||
| assert spec.spectral_axis.unit == spectrum.spectral_axis.unit | ||
| assert spec.spectral_axis.unit == u.um | ||
| assert quantity_allclose(spec.spectral_axis, spectrum.spectral_axis) | ||
| assert quantity_allclose(spec.flux, spectrum.flux) | ||
| assert quantity_allclose(spec.uncertainty.quantity, | ||
|
|
@@ -566,13 +566,13 @@ def test_tabular_fits_multid(tmpdir, ndim, spectral_axis): | |
| spectrum.uncertainty.quantity) | ||
|
|
||
| # Test again, using `column_mapping` to convert to different flux unit | ||
| cmap = {spectral_axis: ('spectral_axis', wlu[spectral_axis]), | ||
| cmap = {spectral_axis: ('spectral_axis', 'THz'), | ||
| 'flux': ('flux', 'erg / (s cm**2 AA)'), | ||
| 'uncertainty': ('uncertainty', None)} | ||
|
|
||
| spec = Spectrum1D.read(tmpfile, format='tabular-fits', column_mapping=cmap) | ||
| assert spec.flux.unit == u.Unit('erg / (s cm**2 AA)') | ||
| assert spec.spectral_axis.unit == spectrum.spectral_axis.unit | ||
| assert spec.spectral_axis.unit == u.THz | ||
| assert quantity_allclose(spec.spectral_axis, spectrum.spectral_axis) | ||
| assert quantity_allclose(spec.flux, spectrum.flux) | ||
| assert quantity_allclose(spec.uncertainty.quantity, | ||
|
|
||
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.
The logging library in python is optimized to use
%sformatting (ref, ref), which is why you'll find it throughout the codebase. I realize it's not strictly enforced, so this is probably a fine change (easier to parse > optimization), but just for future reference.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.
Interesting... but does this line run so much that it warrants optimization?
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.
It's actually
log.debug("'%s'", x.unit)which is probably using.format()internally:Still, the speedup in this context is very modest compared to the time the actual code takes
I find the original version easy enough to parse; just needs to be known since f-strings are otherwise strongly endorsed now in astropy core.
Uh oh!
There was an error while loading. Please reload this page.
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.
@dhomeier is exactly right, the logging package is built to be passed arguments which are evaluated as-needed. In the case of f-strings, interpolation happens before logging visibility criteria is evaluated, which can lead to cases where string errors are raised, nothing gets logged, and the program exits because of the automatic evaluation of
__str__. In%s-style, interpolation happens within the logging package and only as needed. It will therefore be caught as a logging-related issue, an error raised as log message, and the code will continue executing.Additionally, log aggregation (i.e. the sentry package), works because the
%sstring template is the same between similar logging statements. Obviously, we don't make prolific use of this, nor do we experience string-related log-avoiding bugs, but there is a reason that python did not switch the package to using{}or f-style string interpolation with python 3.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.
FWIW, just because
astropyuses it doesn't meanspecutilshas to. I don't thinkastropyuses muchlogginginternally.Though you probably want to document this somewhere in your dev docs, if not already.
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.
No, I also took this solely as a recommendation, but still think it a good idea to synchronise the styles of coordinated packages unless there are more important considerations against it like here.
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 don't think the dev docs here include anything on code style; might be best to just link to https://docs.astropy.org/en/latest/development/codeguide.html
But I believe the performance considerations could be of value there, too, even if logging is currently used very little (found some direct usage of
loggingin the FITS scripts but hardly any of its customAstropyLogger) – maybe just adding a note to the recommendation on f-strings.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 wouldn't bring
AstropyLoggerinto this... 😆 There was a separate discussion, which resulted in doc update clarifying that the logger is forastropyinternal use only.If you want to put the doc upstream in
astropydev docs, I'll have to loop in @embray here since he's working on dev docs revamp over there. They would have a better idea whether this particular doc should go.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 had no intention to switch to
AstropyLoggerhere, was just looking whereloggingis used inside astropy, if at all.If it isn't, there's obviously not much need to mention its own formatting interface. But it probably could not hurt either...