Skip to content

Deprecate mutability of Point, LineString, LinearRing geometries#900

Merged
sgillies merged 5 commits intoshapely:masterfrom
jorisvandenbossche:deprecate-mutating-coords
Jun 5, 2020
Merged

Deprecate mutability of Point, LineString, LinearRing geometries#900
sgillies merged 5 commits intoshapely:masterfrom
jorisvandenbossche:deprecate-mutating-coords

Conversation

@jorisvandenbossche
Copy link
Copy Markdown
Member

xref #782 (Shapely 2.0).

Example of deprecating mutability this for Point:

  • Raise a warning in the coords setter
  • Splitted the tests to more easily isolate the parts that are deprecated (to now filter the warnings, and later to remove in Shapely 2.0)
  • Added one test that actually asserts a warning is raised

If that workflow looks OK, I can do the same for the other geometry types.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Any feedback on this PR?
I know the RFC still needs to be further discussed / approved, but to the extent possible, I would like to already move forward with some of the (less controversial) code changes (I could also target a separate branch than master until the RFC is actually approved?)

import pytest


shapely20_deprecated = pytest.mark.filterwarnings("ignore:Setting:FutureWarning")
Copy link
Copy Markdown
Contributor

@tomplex tomplex May 5, 2020

Choose a reason for hiding this comment

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

Having written a couple of these markers for specifying required GEOS versions, I was wondering if we should put them in a common place (like conftest.py) so they don't need to be re-declared in every file in which they're used. Especially for one like this, which will likely get re-used many times in the coming months.

Copy link
Copy Markdown
Contributor

@tomplex tomplex May 8, 2020

Choose a reason for hiding this comment

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

It was lost on me at the time of commenting that the :Setting: part in the middle is referencing the text of the deprecation warning, and won't work for other messages that don't start with Setting. Should there be a standard message that can be used everywhere deprecations are occurring?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should there be a standard message that can be used everywhere deprecations are occurring?

Yes, that sounds a good idea to have all messages that will be related to "Shapely 2.0 deprecations" have a consistent structure. That makes filtering them out like the above easier with a single pytest marker, and is also more recognizable for users.

(we could actually also go for a warning subclass, for example sphinx has "RemovedInSphinx4Warning": https://github.com/sphinx-doc/sphinx/blob/776ec7957c3407a5ed75dc4369a0042d91698bd1/sphinx/deprecation.py#L21, but that can also easily be adopted later if we want to do so)

I was wondering if we should put them in a common place (like conftest.py) so they don't need to be re-declared in every file in which they're used.

Yes, certainly! It was just because I was only editing a single file here, but once I do the same for the other geometry classes, we certainly need to move it to a general place (and conftest.py seems appropriate for that with pytest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I quite like the idea of a RemovedInShapely20 warning subclass. Would make it much easier for users to filter out all of those warnings with a single go, if they'd like to.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I should have scrolled down here before I recommended the new class above :)

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

@sgillies are you OK with the approach here? If so, I can update this PR to cover all geometry types.

(although RFC 1 is not yet officially approved, I hope I can start on some of the non-controversial parts, like deprecating mutability)

warnings.warn(
"Setting the 'coords' to mutate a Geometry in place is deprecated,"
" and will not be possible any more in Shapely 2.0",
FutureWarning, stacklevel=2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jorisvandenbossche what would you think about adding a new ShapelyDeprecationWarning as recommended in
https://www.python.org/dev/peps/pep-0565/#additional-use-case-for-futurewarning ?

For library and framework authors that want to ensure their API compatibility warnings are more reliably seen by their users, the recommendation is to use a custom warning class that derives from DeprecationWarning in Python 3.7+, and from FutureWarning in earlier versions.

@sgillies
Copy link
Copy Markdown
Contributor

@jorisvandenbossche I'm in favor of this 👍 Let's do consider a new shapely warning class.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

jorisvandenbossche commented May 27, 2020

I added a ShapelyDeprecationWarning (we can still bike shed over the name, eg whether we should have a specific one with "Shapely 2.0" in its name).
I added it to shapely.errors, since that seemed most related submodule, but it's of course not an error, so also happy with making a new shapely.warnings submodule if preferred.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Also a workflow question: do I continue here in this PR with doing the same for the other geometry types, or do you prefer to keep that for a separate PR(s)?

@sgillies
Copy link
Copy Markdown
Contributor

@jorisvandenbossche it's all the same to me, one or multiple PRs as you prefer.

@jorisvandenbossche jorisvandenbossche changed the title Deprecate mutability of Point geometry Deprecate mutability of Point, LineString, LinearRing geometries Jun 5, 2020
@jorisvandenbossche
Copy link
Copy Markdown
Member Author

OK, I added deprecation warnings for linestrings and linearrings as well (I think that's all, since collections' coords are not directly mutable (only their parts), and the same for polygons and its rings)

So this should be ready for review / merge

@sgillies sgillies added this to the 1.8 milestone Jun 5, 2020
"""
Warning for features that will be removed or behaviour that will be
changed in a future release.
"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

self._set_coords(coordinates)
ret = geos_linestring_from_py(coordinates)
if ret is not None:
self._geom, self._ndim = ret
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jorisvandenbossche I appreciate how we will be able to just delete _set_coords in the future. Thank you!

@sgillies sgillies merged commit ea25f8c into shapely:master Jun 5, 2020
@jorisvandenbossche jorisvandenbossche deleted the deprecate-mutating-coords branch June 5, 2020 17:42
@jorisvandenbossche
Copy link
Copy Markdown
Member Author

Then in our own tests we should convert these warnings to errors?

It seems you deleted this comment (or I don't find it back in the github UI), but yes, we could do that, to ensure that we are explicit in the tests about what is deprecated (and don't miss a consequence elsewhere in the package).
The @shapely20_deprecated marks tests we know are testing isolated deprecated behaviour, and then none of the other tests should raise this warning. And we can let pytest detect if that still happens.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

And thanks for merging!
I will continue with some of the other deprecations (I think the adapter/proxy classes are also quite uncontroversial to already start with deprecating?)

@sgillies
Copy link
Copy Markdown
Contributor

sgillies commented Jun 5, 2020

Excellent! I'm really excited about getting a 1.8.0 out. I've got time this afternoon to review tickets and do some release planning. The sooner, the better. Maybe we can even skip a 1.7.1.

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.

3 participants