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

TypeError when creating GeoDataFrame with column named "geometry" #602

Open
kuanb opened this Issue Oct 28, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@kuanb

kuanb commented Oct 28, 2017

Using: geopandas-cython

Let's say I have the below table:
image

I convert the geometry column to Shapely objects like so:

stl_geoms = [loads(s) for s in stl_df.geometry.values]
stl_gp_geoms = gpd.GeoSeries(stl_geoms)

I then attempt to create a GeoDataFrame in the cython branch of GeoPandas like so:

stl_gdf = gpd.GeoDataFrame(stl_df, geometry=stl_gs)

In the main branch of GeoPandas, this would work. The geometry series provide via the kwarg would override the one existing in the stl_df (type string).

In the Cython version, it attempts to use the string column and errors. Traceback:

----------------------------------------------------------------------
AttributeError                       Traceback (most recent call last)
/code/geopandas/geopandas/vectorized.pyx in geopandas.vectorized.from_shapely()

AttributeError: 'str' object has no attribute '__geom__'

During handling of the above exception, another exception occurred:

TypeError                            Traceback (most recent call last)
<ipython-input-54-5b408237dab1> in <module>()
      1 # Convert to a GeoDataFrame
----> 2 stl_gdf = gpd.GeoDataFrame(stl_df)

/code/geopandas/geopandas/geodataframe.py in __init__(self, *args, **kwargs)
    106             arg = arg.copy()
    107             geom = arg.pop(geometry)
--> 108             geom = coerce_to_geoseries(geom, name=geometry)
    109             gs[geometry] = geom
    110 

/code/geopandas/geopandas/geodataframe.py in coerce_to_geoseries(x, **kwargs)
     28         kwargs['name'] = kwargs.get('name', x.name)
     29         kwargs['index'] = kwargs.get('index', x.index)
---> 30         return GeoSeries(vectorized.from_shapely(x.values), **kwargs)
     31     if isinstance(x, Iterable):
     32         return GeoSeries(vectorized.from_shapely(list(x)), **kwargs)

/code/geopandas/geopandas/vectorized.pyx in geopandas.vectorized.from_shapely()

/code/geopandas/geopandas/vectorized.pyx in geopandas.vectorized.from_shapely()

TypeError: Inputs to from_shapely must be shapely geometries. Got POLYGON ((-90.22110299999999 38.57679799999999, -90.220378 38.57713700000001, -90.21906 ...-90.22110299999999 38.57679799999999))
@jorisvandenbossche

This comment has been minimized.

Show comment
Hide comment
@jorisvandenbossche

jorisvandenbossche Oct 30, 2017

Member

@kuanb Thanks for reporting! Yes, the geodataframe constructor can use some more love (there are many possible cases the old one could handle, and the test coverage was not that good, so difficult to check whether the new implementation can fully do the same).

Opened a PR that should fix this: #604

Member

jorisvandenbossche commented Oct 30, 2017

@kuanb Thanks for reporting! Yes, the geodataframe constructor can use some more love (there are many possible cases the old one could handle, and the test coverage was not that good, so difficult to check whether the new implementation can fully do the same).

Opened a PR that should fix this: #604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment