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

ENH: support missing values in dissolve #1477

Closed
MAGALLANESJoseManuel opened this issue Jun 20, 2020 · 7 comments
Closed

ENH: support missing values in dissolve #1477

MAGALLANESJoseManuel opened this issue Jun 20, 2020 · 7 comments

Comments

@MAGALLANESJoseManuel
Copy link

In R, after using dissolve, I get missing values. If I use dissolve in geopandas, the missing values in the 'by=' are not considered, and all polygons have non-missing values...how can I keep them? (as in R)

@martinfleis
Copy link
Member

Can you show an reproducible example illustrating the behaviour? I think I understand what do you mean, but just to be sure.

@MAGALLANESJoseManuel
Copy link
Author

Let me give you this quickly...I have this:
image

As you see WINNEREP has missing values. Then I dissolve:
image

As I WINNEREP has two values (true/false) expect that dissolving produsces 3 geometries, one of them for missing values in WINEREP, but it does not:
image

In R, you get the missing after dissolving:
allZipREP=ms_dissolve(allZipBetter,field = "winnerREP")

image

How can I achieve the same as in R. Thanks in advance!

@jorisvandenbossche
Copy link
Member

This is the pandas groupby behaviour, which drops missing values. In the next pandas release, however, this is a new feature to preserve missing values: pandas-dev/pandas#30584
So then we can also make this available in geopandas' dissolve.

@martinfleis
Copy link
Member

@MAGALLANESJoseManuel As a workaround in the meantime, you can generate NaN-based geometry manually and append it to the result of dissolve.

nan_geom = allZipBetter[allZipBetter.winnerREP.isna()].unary_union

@martinfleis martinfleis changed the title dissolve and missing values ENH: support missing values in dissolve Jun 21, 2020
@mgmanalili
Copy link

I have the same issue. The column used in dissolve 'by' disappears. Is there any way to implement something like, keep=True?

@martinfleis
Copy link
Member

@mgmanalili I don't think that is the issue described above. The column used in dissolve is used as an index in the dissolved GeoDataFrame, it does not disappear. If you want to have it as a regular column, you can call reset_index() after dissolving.

@martinfleis
Copy link
Member

dropna keyword has been implemented. Closing.

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

No branches or pull requests

4 participants