Skip to content
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

Migrate to Shapely 2.0+ #22

Merged
merged 32 commits into from
Feb 6, 2025
Merged

Conversation

joseph-sch
Copy link
Contributor

@joseph-sch joseph-sch commented Jan 27, 2025

This Pull Request updates the codebase of solarfactors to support Shapely 2.0+ instead of Shapely < 2, making it compatible with Python 3.12 and later, also allowing upgrade to NumPy 2.0+ (Shapely started support for NumPy 2.0+ in version 2.0.4).

The primary change involves refactoring the use of Shapely classes to adopt composition instead of inheritance, aligning with Shapely's updated design principles. Classes in solarfactors that previously inherited from Shapely classes (e.g., Polygon, Point, etc.) have been refactored to use composition. Shapely objects are now stored as attributes rather than directly subclassed.

Updated methods and properties to delegate functionality to the Shapely object (e.g., calling self.geometry.length instead of directly accessing inherited properties).

Confirmed that tests run successfully with Shapely 2.0.6 on Python 3.11, with NumPy 2.2.2.

I don't have a proper benchmark, but I can confirm that the tests are not slower than in the main version.

Along the way, I refreshed the README and also modified code to prevent most (but not all) RuntimeWarning occurrences.

@joseph-sch joseph-sch changed the title Migrate to Shapely 2.0 Migrate to Shapely 2.0.6 Jan 27, 2025
@joseph-sch joseph-sch changed the title Migrate to Shapely 2.0.6 Migrate to Shapely 2.0+ Jan 27, 2025
@joseph-sch joseph-sch marked this pull request as ready for review January 27, 2025 14:46
We were getting the following error: "The sphinx.configuration key is missing. This key is now required, see our blog post for more information."

With the following blog post link:
https://about.readthedocs.com/blog/2024/12/deprecate-config-files-without-sphinx-or-mkdocs-config/
TypeError: not all arguments converted during string formatting
@joseph-sch
Copy link
Contributor Author

joseph-sch commented Jan 27, 2025

The issues with the documentation were resolved, see https://solarfactors--22.org.readthedocs.build/en/22/ - but there are quite a few things that still need to be done:

@joseph-sch
Copy link
Contributor Author

@kandersolar what do you think? I wasn't aware of your PR #4 when I started working on that, but I see PR #4 is still a draft - besides, I suppose that using Shapely is better than custom implementation of the distance and other methods, isn't it?

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing @joseph-sch! Thank you very much for this PR, it has been sorely needed for some time.

These changes seem reasonable to me, although unfortunately I'm not familiar enough with shapely to say more than that just by looking at the code. So I want to experiment with it locally before merging. FYI it may be some days before I am able to complete that.

In the meantime, a couple trivial edits below :)

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
README.rst Show resolved Hide resolved
@kandersolar
Copy link
Member

The issues with the documentation were resolved, see https://solarfactors--22.org.readthedocs.build/en/22/ - but there are quite a few things that still need to be done:

Let's handle these in follow-up PRs, to keep this one manageable.

@kandersolar kandersolar added this to the 1.5.4 milestone Jan 28, 2025
@joseph-sch
Copy link
Contributor Author

Amazing @joseph-sch! Thank you very much for this PR, it has been sorely needed for some time.

These changes seem reasonable to me, although unfortunately I'm not familiar enough with shapely to say more than that just by looking at the code. So I want to experiment with it locally before merging. FYI it may be some days before I am able to complete that.

In the meantime, a couple trivial edits below :)

Of course, these changes need to be checked beyond the unit tests that are implemented within the project - in particular, run tests of pvlib against this version.

Thank you for the edits and feedback.

Looking forward to your informed opinion after you've run further tests.

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing this branch with shapely 2.0.6, with the last release of solarfactors (1.5.3) and shapely 1.8.5.post1, I detect no change in runtime, no issue in the solarfactors and pvlib test suites, and identical simulation results when running simple manual tests.

@anomam do you want to review as well? I think I'm happy with this PR.

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@anomam
Copy link
Contributor

anomam commented Jan 31, 2025

Thanks a lot for this PR @joseph-sch , Shapely v2 also resolved a lot of memory leaks that caused my previous team many headaches so it's a much needed upgrade 🙏
I also appreciate the use of composition instead of inheritance for shapely objects, it should make my dream of removing shapely as a dependency a little bit closer to reality... 😭
LGTM! 🚀

joseph-sch and others added 2 commits February 4, 2025 10:38
Co-authored-by: Kevin Anderson <[email protected]>
Co-authored-by: Kevin Anderson <[email protected]>
@kandersolar
Copy link
Member

Indeed fixing this issue was a primary motivation for forking solarfactors! It is very nice to see this finally resolved. Thanks again @joseph-sch, and hopefully you have time for more contributions in the future :)

@kandersolar kandersolar merged commit 97569f8 into pvlib:main Feb 6, 2025
13 of 14 checks passed
@kandersolar
Copy link
Member

I will fix the linter flags in a follow-up PR, as it looks like this one is not configured to allow maintainers to edit.

kandersolar added a commit to kandersolar/solarfactors that referenced this pull request Feb 6, 2025
@kandersolar kandersolar mentioned this pull request Feb 6, 2025
8 tasks
kandersolar added a commit that referenced this pull request Feb 6, 2025
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.

Error installing solarfactors on Py3.12 due to Shapely pinned versions
3 participants