Skip to content

Update shapely to >=2.0.1,<3.0.0#1331

Merged
lee1043 merged 3 commits intoPCMDI:mainfrom
xylar:update-shapely
Oct 13, 2025
Merged

Update shapely to >=2.0.1,<3.0.0#1331
lee1043 merged 3 commits intoPCMDI:mainfrom
xylar:update-shapely

Conversation

@xylar
Copy link
Contributor

@xylar xylar commented Oct 13, 2025

This pull request improves compatibility with newer versions of the shapely library and refines how polygonal geometries are handled in precipitation metrics code. The main changes include updating dependency constraints and making the code more robust to different geometry types returned by shapely operations. This ensures consistent behavior across shapely versions and prevents errors when working with simplified geometries.

Dependency updates:

  • Updated the shapely dependency constraint in both conda-env/ci.yml and conda-env/dev.yml to allow any version >=2.0.1 and <3.0.0, ensuring compatibility with future shapely 2.x releases. [1] [2]

Geometry handling improvements:

  • In CalcMetricsDomain3Clust and MedDomain3Clust functions (lib_precip_distribution.py), added logic to handle cases where MultiPolygon.simplify may return a Polygon or GeometryCollection. The code now coerces the result to a MultiPolygon containing only polygonal components, improving robustness to geometry type changes in shapely >=2. [1] [2]
  • In CalcMetricsDomainAR6 and MedDomainAR6, clarified and corrected the construction of MultiPolygon objects: when region polygons are already created, they are passed directly to MultiPolygon, preventing unnecessary wrapping and potential errors. [1] [2] [3]

Fixes #1330

@xylar
Copy link
Contributor Author

xylar commented Oct 13, 2025

@lee1043, could you take a look at this when you have time? @andrewdnolan, just letting you know I took care of this.

@andrewdnolan
Copy link

Thanks @xylar!

@lee1043
Copy link
Contributor

lee1043 commented Oct 13, 2025

@xylar thanks for the PR! Confirmed that the PMP code tested with demo 1b notebook works fine with shapely 2.1.X versions.

@lee1043 lee1043 merged commit 826c123 into PCMDI:main Oct 13, 2025
7 checks passed
@xylar xylar deleted the update-shapely branch October 13, 2025 18:30
@xylar
Copy link
Contributor Author

xylar commented Oct 13, 2025

And thanks for this especially!

If you can do a 4.0.1 or 4.1.0 release with this update, that would be really helpful to us.

@lee1043
Copy link
Contributor

lee1043 commented Oct 13, 2025

@xylar Thanks for the comment! I am working on updating the build number for 4.0.0 (conda-forge/pcmdi_metrics-feedstock#55), but do you prefer having new version release?

@xylar
Copy link
Contributor Author

xylar commented Oct 13, 2025

@lee1043, yes you cannot simply update the build number if there have been code changes. You need to do a new release. Changing the build number leaves the code entirely unchanged and just updates the recipe for making the conda package. (Unless you go through the trouble to patch the code on conda-forge, which is to be avoided.)

@lee1043
Copy link
Contributor

lee1043 commented Oct 13, 2025

@xylar Thanks for helping me better understand this! Sure, I can bump the version to 4.0.1 and release through the conda channel today.

@xylar
Copy link
Contributor Author

xylar commented Oct 13, 2025

Perfect! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upper constraint for shapely needs to be relaxed for e3sm-unified

3 participants