Skip to content

Commit d5ef041

Browse files
authored
Fix a few xfailed tests (geopandas#574)
* Fix some tests in geodataframe * fix GeoSeries.astype(str) * respond to comments
1 parent 9aa9808 commit d5ef041

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

geopandas/_block.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,15 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
151151
raise on an except if raise == True
152152
"""
153153

154-
if dtype != np.object_:
154+
if dtype == np.object_:
155+
values = self.to_dense()
156+
elif dtype == str:
157+
values = np.array(list(map(str, self.to_dense())))
158+
else:
155159
if errors == 'raise':
156160
raise TypeError('cannot astype geometries')
157-
values = self.values
161+
else:
162+
values = self.to_dense()
158163

159164
if copy:
160165
values = values.copy()

geopandas/geodataframe.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ def __init__(self, *args, **kwargs):
6565
crs = kwargs.pop('crs', None)
6666

6767
geometry = kwargs.pop('geometry', 'geometry')
68-
[arg] = args
68+
if not args:
69+
arg = []
70+
else:
71+
[arg] = args
6972

7073
if isinstance(arg, BlockManager):
7174
super(GeoDataFrame, self).__init__(arg, **kwargs)
@@ -173,7 +176,8 @@ def set_geometry(self, col, drop=False, inplace=False, crs=None):
173176
Set the GeoDataFrame geometry using either an existing column or
174177
the specified input. By default yields a new object.
175178
176-
The original geometry column is replaced with the input.
179+
The original geometry column is replaced with the input. The geometry
180+
column will have the same name as the selected column.
177181
178182
Parameters
179183
----------
@@ -195,7 +199,6 @@ def set_geometry(self, col, drop=False, inplace=False, crs=None):
195199
Returns
196200
-------
197201
geodataframe : GeoDataFrame
198-
199202
"""
200203
if inplace:
201204
frame = self

geopandas/tests/test_geodataframe.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ def test_from_postgis_custom_geom_col(self):
489489

490490
validate_boro_df(df, case_sensitive=False)
491491

492-
@pytest.mark.cython
493-
@pytest.mark.xfail(reason="GEOPANDAS-CYTHON")
494492
def test_dataframe_to_geodataframe(self):
495493
df = pd.DataFrame({"A": range(len(self.df)), "location":
496494
list(self.df.geometry)}, index=self.df.index)
@@ -504,9 +502,8 @@ def test_dataframe_to_geodataframe(self):
504502
gf2 = df.set_geometry('location', crs=self.df.crs, drop=True)
505503
assert isinstance(df, pd.DataFrame)
506504
assert isinstance(gf2, GeoDataFrame)
507-
assert gf2.geometry.name == 'geometry'
508-
assert 'geometry' in gf2
509-
assert 'location' not in gf2
505+
assert gf2.geometry.name == 'location'
506+
assert 'location' in gf2
510507
assert 'location' in df
511508

512509
# should be a copy
@@ -694,7 +691,6 @@ def test_from_frame_specified_geometry(self):
694691
df.geometry
695692

696693
@pytest.mark.cython
697-
@pytest.mark.xfail(reason="GEOPANDAS-CYTHON")
698694
def test_only_geometry(self):
699695
df = GeoDataFrame(geometry=[Point(x, x) for x in range(3)])
700696
check_geodataframe(df)
@@ -716,7 +712,6 @@ def test_without_geometries(self):
716712
assert list(gdf.x) == [1]
717713

718714
@pytest.mark.cython
719-
@pytest.mark.xfail(reason="GEOPANDAS-CYTHON")
720715
def test_empty(self):
721716
df = GeoDataFrame()
722717
assert type(df) == GeoDataFrame

geopandas/tests/test_pandas_methods.py

-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def test_assign(df):
109109

110110

111111
@pytest.mark.cython
112-
@pytest.mark.xfail(reason="GEOPANDAS-CYTHON")
113112
def test_astype(s):
114-
115113
with pytest.raises(TypeError):
116114
s.astype(int)
117115

geopandas/vectorized.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ cpdef from_shapely(object L):
127127
try:
128128
geos_geom = <np.uintp_t> g.__geom__
129129
except AttributeError:
130-
msg = ("Inputs to from_shapely must be shapely eometries. "
130+
msg = ("Inputs to from_shapely must be shapely geometries. "
131131
"Got %s" % str(g))
132132
raise TypeError(msg)
133133
geom = GEOSGeom_clone_r(handle, <GEOSGeometry *> geos_geom) # create a copy rather than deal with gc

0 commit comments

Comments
 (0)