Repository navigation
Refactor representations as a module - #14792
Conversation
Only change is to use absolute imports for other modules in astropy.coordinates.
Just copied text over to new file and added required imports on top. In __init__.py, added import from new .cartesian at bottom to avoid circular imports.
Again, just adding imports on top, and an import from cylindrical at the bottom of __init__.py.
With usual local imports on top, and import from spherical at bottom of __init__.py. Also change to import in cyclindrical, and adjustment of one test, since the location of the classes now has changed. Not yet changing the locations in the failing doctests.
Now __init__.py can be cleaned up. Import some variables for backward compatibility. For the one private one only used in a test, change the test. Change imports on top of cartesian, etc., to be from .base.
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
|
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.
|
nstarman
left a comment
There was a problem hiding this comment.
This looks good and was very easy to review, stepping though the commits!
| from .base import DIFFERENTIAL_CLASSES | ||
| from .base import DUPLICATE_REPRESENTATIONS | ||
| from .base import REPRESENTATION_CLASSES |
There was a problem hiding this comment.
Would it be worthwhile to make these read-only?
| from .base import DIFFERENTIAL_CLASSES | |
| from .base import DUPLICATE_REPRESENTATIONS | |
| from .base import REPRESENTATION_CLASSES | |
| from types import MappingProxyType | |
| from .base import MappingProxyType(DIFFERENTIAL_CLASSES) | |
| from .base import MappingProxyType(DUPLICATE_REPRESENTATIONS) | |
| from .base import MappingProxyType(REPRESENTATION_CLASSES) |
Or to deprecate their access from here?
There was a problem hiding this comment.
I agree it should be deprecated, which is relatively easy to do with __getattr__, but think it is best to do as a separate PR after this, so one would not be distracted by all the other changes.
| "astropy.coordinates.representation.cartesian.CartesianRepresentation", | ||
| "astropy.coordinates.representation.spherical.UnitSphericalRepresentation", | ||
| "astropy.coordinates.representation.spherical.RadialRepresentation", | ||
| "astropy.coordinates.representation.spherical.SphericalRepresentation", | ||
| "astropy.coordinates.representation.spherical.PhysicsSphericalRepresentation", | ||
| "astropy.coordinates.representation.cylindrical.CylindricalRepresentation", | ||
| "astropy.coordinates.representation.cartesian.CartesianDifferential", | ||
| "astropy.coordinates.representation.spherical.UnitSphericalDifferential", | ||
| "astropy.coordinates.representation.spherical.SphericalDifferential", | ||
| "astropy.coordinates.representation.spherical.UnitSphericalCosLatDifferential", | ||
| "astropy.coordinates.representation.spherical.SphericalCosLatDifferential", | ||
| "astropy.coordinates.representation.spherical.RadialDifferential", | ||
| "astropy.coordinates.representation.spherical.PhysicsSphericalDifferential", | ||
| "astropy.coordinates.representation.cylindrical.CylindricalDifferential", |
There was a problem hiding this comment.
Is there a way to avoid changing the path? All the classes are imported to astropy.coordinates.representation.
There was a problem hiding this comment.
In cosmology I use a mapping to map from the fully-qualified path to a preferred path, e.g. astropy.coordinates.representation.cartesian.CartesianRepresentation to astropy.coordinates.CartesianRepresentation
There was a problem hiding this comment.
You already opened #13689 for that purpose - where you made the suggestion of using entrypoints, which seems just right for this.
|
@nstarman - I think all your points are good ones - but also feel best for this PR is to make only the most minimal changes... |
|
OK, will merge now! |
|
|
|
Of course, mostly exactly the same lines. And a file with 3600 lines of code really is overly long! |
This is a reimplementation of #13688, redoing the refactoring to ensure that (1) there are no changes other than what is strictly necessary, and (2) any commits since that time are included (I restarted when I noticed #13688 had an import of a deprecated function that had been removed, and worried there were other changes). I avoided introducing any
__all__in the submodules, for now just relying on importing what is relevant in the new__init__.py. I cherry-picked commits from #13688 that fix errors in the documentation and in serialization because of the class name changes (making a few small changes in the process). Like in #13688, I also keep a few variables in__init__.pythat are not exported, but are used in tests, for backward compatibility.I mostly did this since I still think the refactoring is a very good idea, and it would be helpful for #14763, which introduces more general geodetic representations, if there is a place to put them.
Ping @nstarman who did #13688 and @eerovaher who had requested changes to it, mostly to ensure we make no actual code changes (which I think I ensured!); if we all still think this is a good idea, we should probably get it in sooner rather than later... (thankfully,
representationsis quite mature, so I don't foresee problems with backporting to 5.3).p.s. The commits are meant to be fairly logical: for all
pytest -P coordinatesworked (except a few names in doctests aftersphericalis factored out).EDIT: Close #13688