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

Being able to instanciate empty GeoDataFrame #121

Open
rderollepot opened this issue Jun 19, 2023 · 1 comment
Open

Being able to instanciate empty GeoDataFrame #121

rderollepot opened this issue Jun 19, 2023 · 1 comment

Comments

@rderollepot
Copy link

Is your feature request related to a problem? Please describe.

I have a workflow in which I process a geopandas GeoDataFrame in order to draw a map on a dashboard. At some point, I wish to make use of datashader reduction capabilities and thus, I convert my df into a spatialpandas GeoDataFrame. My dashboard allows to set filters which can lead my GeoDataFrame to be empty, and in that case, the conversion into a spatialpandas GeoDataFrame fails:

ValueError: A spatialpandas GeoDataFrame must contain at least one spatialpandas GeometryArray column

This led me to realize that spatialpandas does not allow the instanciation of an empty DataFrame, or at least not in the way pandas and geopandas allow it:

import pandas as pd
import geopandas as gpd
import spatialpandas as spd

pd.DataFrame() # works
gpd.GeoDataFrame() # works
spd.GeoDataFrame() # fails

Describe the solution you'd like

I would like to be able to generate empty spatialpandas GeoDataFrame.

Describe alternatives you've considered

An alternative I have is to first convert into a spatialpandas GeoDataFrame, and then filter this new DataFrame. When I do it in this order, query() is able to return an empty spatialpandas GeoDataFrame if there are indeed no matching results.

@rderollepot rderollepot changed the title Being able to instanciate empty (Geo)DataFrame Being able to instanciate empty GeoDataFrame Jun 19, 2023
@ianthomas23
Copy link
Member

This should be fairly easy to implement, the question is whether it will break anything because of the previously valid assumption that a GeoDataFrame always contains data. I'll take a look.

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

2 participants