-
Notifications
You must be signed in to change notification settings - Fork 63
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
Return GeoDataFrame in the to_dataframe function #1681
Return GeoDataFrame in the to_dataframe function #1681
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good approach. However, it requires some changes into the logic, and to cover these changes with unit tests.
return dataframe | ||
gdf = GeoDataFrame(dataframe) | ||
|
||
if has_geometry(dataframe): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function has_geometry
check the geometry of an existing GeoDataFrame, not for a DataFrames, so this won't work. We should implement the following logic instead:
- Check if the existing dataframe contains a raw geom column if:
- The entity is a Geography or
- The entity is a Dataset and add_geom is True
- In every case check that the column is there and can be decoded:
- decode_geometry(df['geom'])
- If it works, create the GeoDataFrame with that geometry
- PD: we need to decide if we should keep the original geom column or not
@@ -75,6 +75,7 @@ def test_dataset_to_csv_private(self): | |||
def test_dataset_to_dataframe_public(self): | |||
df = public_dataset.to_dataframe(self.credentials, limit=PUBLIC_LIMIT) | |||
assert isinstance(df, GeoDataFrame) | |||
assert df.head().geom.type == 'Polygon' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could access directly the column assert df.geom.type == 'Polygon'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, changing it 👍
GeoDataFrame
in theto_dataframe
functionassert isinstance(df, GeoDataFrame)
)