Refactoring of the parsing of simple units, moving short-circuit up#17012
Refactoring of the parsing of simple units, moving short-circuit up#17012mhvk wants to merge 4 commits intoastropy:mainfrom
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.
|
|
Benchmarks are a bit weird: simple units are faster, as expected, but quantity initialization has slowed down? Will try to rerun, especially given the large variance, but for the record: EDIT: OK, the rerun of the benchmarks only shows the expected improvement (plus a still flaky run on main): |
0cf509c to
7cba61b
Compare
eerovaher
left a comment
There was a problem hiding this comment.
This is an alternative to #17004 that does not rely on private methods
The difference between public and private API is that in private API we are allowed to make breaking changes whenever we want. This means downstream developers should avoid using our private API, but it does not mean that we ourselves should be forbidden from using it. I don't think using private API in #17004 is a problem, especially given that it is using private API from units.
But it turns out that for FITS at least, some short-circuiting has to be done...
Special cases like FITS in this pull request should be avoided if possible because they make the code more difficult to understand and to maintain. There are no such special cases in #17004.
|
Hmm, looking at your PR again, I think it is really equally simple (after the other changes made), and does cover the FITS case. So, let me close this one in favour of #17004. |
This is an alternative to #17004 that does not rely on private methods, and removes the short-circuiting from the unit parser. It builds on #17011, since removing the short-circuit from the unit parser brought out quite a few bugs. (EDIT: #17011 is merged, so only 3 commits left.) But it turns out that for FITS at least, some short-circuiting has to be done, since it weirdly defines a unit "deg C", which would in normal parsing become "degrees Coulomb" (and which we really do not want in a composite unit!).
Note that while the last commit is labelled performance, this is only relative to the case where the short circuit is not present at all. Relative to main, performance benefits are modest.