Skip to content

Commit

Permalink
Fix constructor logic when geometry and columns both provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Aug 18, 2017
1 parent e288068 commit 7c0e0b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion geopandas/geodataframe.py
Expand Up @@ -83,7 +83,7 @@ def __init__(self, *args, **kwargs):
if isinstance(v, GeoSeries):
if 'columns' in kwargs:
columns = kwargs['columns'].copy()
columns.pop(i)
columns.remove(k)
kwargs['columns'] = columns
gs[k] = arg.pop(k)
kwargs['index'] = v.index # TODO: assumes consistent index
Expand Down
12 changes: 12 additions & 0 deletions geopandas/tests/test_geodataframe.py
Expand Up @@ -520,3 +520,15 @@ def test_set_geometry_null():
def test_constructor_without_geometries():
gdf = GeoDataFrame({'x': [1]})
assert list(gdf.x) == [1]


def test_constructor_column_ordering():
geoms = [Point(1, 1), Point(2, 2), Point(3, 3)]
gs = GeoSeries(geoms)
gdf = GeoDataFrame({'a': [1, 2, 3], 'geometry': gs},
columns=['geometry', 'a'],
index=pd.Index([0, 0, 1]),
geometry='geometry')

assert gdf.geometry._geometry_array is gs._geometry_array
assert gdf.geometry._geometry_array.data.all()

0 comments on commit 7c0e0b3

Please sign in to comment.