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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

joseph-sch
Copy link

@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
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
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
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.

If you wish to contribute, you can start by forking and cloning the repository, and then installing pvfactors using pip_ in the root folder of the package:
Contributions are needed in order to improve solarfactors.

If you wish to contribute, you can start by forking and cloning the repository, and then installing openfactors using pip_ in the root folder of the package:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you wish to contribute, you can start by forking and cloning the repository, and then installing openfactors using pip_ in the root folder of the package:
If you wish to contribute, you can start by forking and cloning the repository, and then installing solarfactors using pip_ in the root folder of the package:

oops, one more

Comment on lines +241 to +245
Install test dependencies by running:

.. code:: sh

$ pip install pytest mock
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Install test dependencies by running:
.. code:: sh
$ pip install pytest mock
Install test dependencies using the ``test`` extra:
.. code:: sh
$ pip install .[test]

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
2 participants