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

Avoid renaming geometry if geometry name is already GEOM_COLUMN_NAME #1726

Merged
merged 1 commit into from
Mar 17, 2021

Conversation

Mmoncadaisla
Copy link
Contributor

Context

In this small PR from Support we aim to fix an undesired behavior when using the rename_geometry method from the to_carto function.

Since the latest additions to GeoPandas, if the column name to be used as input for the referred function is already present in the GeoDataFrame columns, an error would be raised, which seems to break data uploads when the geometry column is named the_geom.

Further details can be found in this CH story.

PR changes

io/carto.py: Avoid using the rename_geometry method if the GeoDataFrame's geometry column is named as GEOM_COLUMN_NAME (the_geom)

Result with PR changes

>>> import cartoframes
>>> cartoframes.auth.set_default_credentials(username='mmoncada', api_key='master_api_key')
>>> gdf = cartoframes.read_carto('cod')
>>> gdf.head()
   cartodb_id                                           the_geom  fid  cod_postal
0          18  MULTIPOLYGON (((-2.21981 43.03500, -2.21978 43...    5     20213.0
1          23  MULTIPOLYGON (((-3.05027 37.78892, -3.04790 37...    7     23487.0
2          32  MULTIPOLYGON (((-3.50303 40.52600, -3.50304 40...   10     28864.0
3          39  MULTIPOLYGON (((-2.54156 38.20036, -2.52919 38...   12     23297.0
4          43  MULTIPOLYGON (((-5.95369 37.99535, -5.95369 37...   13     41250.0
>>> cartoframes.to_carto(gdf, 'cod_test_2')
Success! Data uploaded to table "cod_test_2" correctly
'cod_test_2'

@Mmoncadaisla Mmoncadaisla requested a review from Jesus89 March 12, 2021 15:11
@Mmoncadaisla Mmoncadaisla self-assigned this Mar 12, 2021
@Mmoncadaisla Mmoncadaisla merged commit 85f4a9a into develop Mar 17, 2021
@Jesus89 Jesus89 deleted the fix_rename_geometry_to_carto branch March 17, 2021 11:50
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