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

API: Raise warning when overriding a CRS via crs property setter #3088

Merged
merged 17 commits into from
May 31, 2024

Conversation

JohnMoutafis
Copy link
Contributor

@JohnMoutafis JohnMoutafis commented Nov 28, 2023

Refs: #3085
For the current version: Warn the user that tries to manually change a GeoSeries' existing CRS by the property setter (ex. gs.crs = "new crs"), that the setter will be deprecated in future versions and that the set_crs method should be used instead.

@martinfleis
Copy link
Member

As noted in #3085, we'll need to cover both GeoSeries and GeoDataFrame here.

@JohnMoutafis
Copy link
Contributor Author

There seems to be an issue with GeoDataFrame.dissolve trying to set crs through the setter but I cannot wrap my head around were this is happening.
Any suggestions?

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

I've fixed the usage of GeoSeries.crs setter in GeoSeries.set_geometry and pushed one minor commit to ensure_geometry along the same lines.

A consequence of this warning is that due to usage of setter in some places and especially in tests, we have a ton of there warnings in our CI which we should ideally clear, especially if this will raise eventually.

geopandas/geodataframe.py Outdated Show resolved Hide resolved
geopandas/tests/test_crs.py Outdated Show resolved Hide resolved
geopandas/tests/test_geodataframe.py Outdated Show resolved Hide resolved
geopandas/tests/test_geoseries.py Show resolved Hide resolved
geopandas/tests/test_geoseries.py Outdated Show resolved Hide resolved
@jorisvandenbossche
Copy link
Member

@JohnMoutafis would you have time to update for the comments of @martinfleis ?

@JohnMoutafis
Copy link
Contributor Author

@jorisvandenbossche I will try to find some (hopefully soon)

@martinfleis
Copy link
Member

@JohnMoutafis given we'd like to have this included in 1.0 which shall be released hopefully soon, I have pushed some commits myself, mostly resolving my own comments.

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

Thanks for getting this going @JohnMoutafis!

@JohnMoutafis
Copy link
Contributor Author

@martinfleis sorry for not finding the time to handle the requested changes.
Does the PR need anything atm to be merged?
What about the coverage?

@martinfleis
Copy link
Member

I think it is ready to be merged, just want to wait for another review.

The coverage can be ignored I suppose, given the patch has 100%. It tends to be flaky from time to time.

@jorisvandenbossche jorisvandenbossche changed the title MAINT: Raise warning when overriding a CRS via crs property setter API: Raise warning when overriding a CRS via crs property setter May 31, 2024
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@jorisvandenbossche jorisvandenbossche merged commit a45a720 into geopandas:main May 31, 2024
19 of 20 checks passed
Comment on lines +243 to +244
"Overriding the CRS of a GeoSeries that already has CRS."
"This unsafe behavior will be deprecated in future versions."
Copy link
Member

Choose a reason for hiding this comment

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

Sorry a bit late now, but these lines are missing spaces after the full stops inside the quotes (this also happens once above in the geodataframe warning).
I also see in the dev env that the warnings are getting triggered by pandas code in certain tests, which we may want to look into, but I suppose there's still quite a bit of time before the deprecation is enforced.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, missed that in re-reviewing, good catch! Will do a quick follow-up to fix

@jorisvandenbossche
Copy link
Member

I also see in the dev env that the warnings are getting triggered by pandas code in certain tests, which we may want to look into, but I suppose there's still quite a bit of time before the deprecation is enforced.

I think they are being triggered in general in our tests. Looking at the ones in test_geodataframe.py, it seems this comes from doing df.crs = None (i.e. to remove the crs from a df for the test). But replacing that with df = df.set_crs(None, allow_override=True) doesn't work, because we don't accept None.

Do we want to accept None in that method, or do we not raise the warning for the case of assigning None ? (we are not silently replacing a crs, so less need to warn about that)

@martinfleis
Copy link
Member

Yeah, I noted that in #3088 (review) and then forgot about it.

Do we want to accept None in that method, or do we not raise the warning for the case of assigning None ?

I think that we should have a canonical way of removing crs and set_crs(None, allow_override=True) feels like the best way.

In the tests, we can potentially replace that by assigning to the GeometryArray.crs but allowing None in set_crs might be the best.

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.

None yet

4 participants