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

Return GeoDataFrame in the to_dataframe function #1681

Conversation

antoniocarlon
Copy link
Contributor

  • Return GeoDataFrame in the to_dataframe function
  • Modified docstring
  • Added check to the tests (assert isinstance(df, GeoDataFrame))

@antoniocarlon antoniocarlon requested a review from Jesus89 August 26, 2020 09:28
Copy link
Member

@Jesus89 Jesus89 left a 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):
Copy link
Member

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'
Copy link
Member

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'

Copy link
Contributor Author

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 👍

@Jesus89 Jesus89 merged commit 2534486 into develop Aug 27, 2020
@Jesus89 Jesus89 deleted the feature/ch99926/change-dataset-to-dataframe-to-return-geodataframe branch August 27, 2020 12:13
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.

2 participants