Repository navigation
fix(datashader): render_shapes in a non-global coordinate system (#782) - #783
Merged
Merged
Conversation
The datashader branch of _render_shapes requested the canvas extent in a hardcoded "global" CS. When the GeoDataFrame constructor propagates the source element's transform attrs (pandas/geopandas-version dependent), the re-wrapped element carries only the real CS and the "global" lookup in _element_extent_fast raises KeyError. Drop any carried-over transform attr, tag the wrapped element with an identity transform in the resolved coordinate_system, and compute the extent in that CS. Mirrors the points datashader branch.
test_groups_filtering_preserves_transformation hard-asserted that a bare gpd.GeoDataFrame re-wrap strips .attrs (so _prepare_transformation raises). Whether the GeoDataFrame constructor propagates .attrs is pandas/geopandas version dependent, so that assertion fails on stacks that preserve them. Keep the actual #420 guard (the spatialdata-managed element retains its transform after groups filtering) and drop the brittle demonstration block and now-dead re-wrap.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #783 +/- ##
=======================================
Coverage 80.09% 80.10%
=======================================
Files 18 18
Lines 4863 4865 +2
Branches 1080 1080
=======================================
+ Hits 3895 3897 +2
Misses 603 603
Partials 365 365
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #782.
Problem
render_shapes(..., method="datashader")raisesKeyError: 'global'when the shapes element has no"global"coordinate system (e.g. Visium HD data from spatialdata-io, which places elements in a custom CS). Datashader is used explicitly or automatically for >10k shapes, so this breaks thetechnology_visium_hdexample notebooks.Root cause
The datashader branch of
_render_shapeswraps the already-transformed geometry withShapesModel.parse(...)and then requests the canvas extent in a hardcoded"global"CS. Whether theGeoDataFrameconstructor propagates the source element's.attrsis pandas/geopandas-version dependent:my_sample), so the"global"lookup in_element_extent_fastraisesKeyError: 'global'.globalidentity and it silently works.Fix
In the datashader branch (
src/spatialdata_plot/pl/render.py):transformattr before parsing (otherwiseShapesModel.parsewithtransformations=would raiseValueError: Transformations are both specified for the element and also passed as an argument).transformations={coordinate_system: Identity()}— the geometry is already in the target CS.coordinate_systeminstead of the hardcoded"global".This mirrors the already-correct points datashader branch. The working (
global) case is byte-identical — same coordinates, same extent — so no visual baselines change.Notes
method="datashader") and confirmed the fix holds in both attrs regimes (propagated / dropped).test_plot_*are CI-only.