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
PERF: CRS - use WKT for cache and lazy load EPSG code #1322
Conversation
return crs_spec.to_wkt() | ||
|
||
|
||
@cachetools.cached({}, key=_make_crs_key) # type: ignore[misc] | ||
def _make_crs(crs: Union[str, _CRS]) -> Tuple[_CRS, str, Optional[int]]: | ||
if isinstance(crs, str): | ||
def _make_crs(crs: Union[str, int, _CRS]) -> Tuple[_CRS, str, Optional[int]]: |
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.
Allow passing in integer EPSG code.
crs = _CRS.from_user_input(crs) | ||
epsg = crs.to_epsg() |
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.
Remove all to_epsg
calls.
try: | ||
wkt = crs_spec.to_wkt() | ||
except AttributeError: | ||
wkt = None | ||
if wkt is not None: | ||
self._crs, self._str, self._epsg = _make_crs(wkt) | ||
return | ||
try: | ||
epsg = crs_spec.to_epsg() |
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.
Use EPSG as backup to WKT. Likely never used. Will raise exception in the future if no WKT (see: pyproj4/pyproj#1036).
Note: I will be happy to update the tests if this is the desired pattern to move forward with. |
I will have a look at the tests later this week - I suspect some of them are not your fault. |
@snowman2 I think a good chunk of the test issues are due to this no longer working:
With this PR |
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 think the changes I suggest should just about do it. We might need to make some changes to the (experimental) postgis tests as well.
Good catches @SpacemanPaul 👍. I updated the PR based on your comments. |
ade84ea
to
0e6f0aa
Compare
Codecov ReportBase: 92.34% // Head: 92.33% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #1322 +/- ##
===========================================
- Coverage 92.34% 92.33% -0.01%
===========================================
Files 127 127
Lines 13581 13585 +4
===========================================
+ Hits 12541 12544 +3
- Misses 1040 1041 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
epsg = int(crs_str.split(":", maxsplit=1)[-1]) | ||
else: | ||
crs_str = crs | ||
crs = _CRS.from_user_input(crs) |
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.
Always call _CRS.from_user_input
as it supports all of these types. Also, if it is a _CRS
, it just returns the original _CRS
ref.
0e6f0aa
to
1b5cf8b
Compare
def _make_crs(crs: Union[str, int, _CRS]) -> Tuple[_CRS, str, Optional[int]]: | ||
epsg = False | ||
crs = _CRS.from_user_input(crs) | ||
crs_str = crs.srs |
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.
srs
is the attribute for the user input string.
1b5cf8b
to
d2d7d0d
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.
Thanks heaps @snowman2
Thanks @SpacemanPaul 👍 |
Closes #1321
If this is merged, I will be happy to port it into odc-geo.