Skip to content
Commits on Source (4)
Changes
=======
Version 0.6.1 (July 11, 2019)
-----------------------------
Small bug-fix release fixing a few regressions:
- Fix `astype` when converting to string with Multi geometries (#1145) or when converting a dataframe without geometries (#1144).
- Fix `GeoSeries.fillna` to accept `np.nan` again (#1149).
Version 0.6.0 (September 27, 2019)
----------------------------------
......
python-geopandas (0.6.0-2) UNRELEASED; urgency=medium
python-geopandas (0.6.1-1) unstable; urgency=medium
* Team upload.
* New upstream release.
* Bump Standards-Version to 4.4.1, no changes.
-- Bas Couwenberg <sebastic@debian.org> Mon, 30 Sep 2019 19:52:49 +0200
-- Bas Couwenberg <sebastic@debian.org> Sun, 13 Oct 2019 08:41:53 +0200
python-geopandas (0.6.0-1) unstable; urgency=medium
......
......@@ -22,8 +22,8 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames = " (HEAD -> master, tag: v0.6.0)"
git_full = "da3aef6d4bbf0b2308aaeed36e0b5904fd7526ec"
git_refnames = " (tag: v0.6.1)"
git_full = "7df43d1375fee9174eb9314567c2464ed2d7e7a1"
keywords = {"refnames": git_refnames, "full": git_full}
return keywords
......
......@@ -828,6 +828,9 @@ class GeometryArray(ExtensionArray):
"""
if method is not None:
raise NotImplementedError("fillna with a method is not yet supported")
if _isna(value):
value = None
elif not isinstance(value, BaseGeometry):
raise NotImplementedError(
"fillna currently only supports filling with a scalar geometry"
......@@ -865,6 +868,11 @@ class GeometryArray(ExtensionArray):
return self.copy()
else:
return self
elif pd.api.types.is_string_dtype(dtype) and not pd.api.types.is_object_dtype(
dtype
):
return to_wkt(self).astype(dtype, copy=False)
else:
return np.array(self, dtype=dtype, copy=copy)
def isna(self):
......
......@@ -708,11 +708,14 @@ class GeoDataFrame(GeoPandasBase, DataFrame):
df = super(GeoDataFrame, self).astype(dtype, copy=copy, errors=errors, **kwargs)
try:
df = geopandas.GeoDataFrame(df, geometry=self._geometry_column_name)
return df
except TypeError:
df = pd.DataFrame(df)
return df
geoms = df[self._geometry_column_name]
if is_geometry_type(geoms):
return geopandas.GeoDataFrame(df, geometry=self._geometry_column_name)
except KeyError:
pass
# if the geometry column is converted to non-geometries or did not exist
# do not return a GeoDataFrame
return pd.DataFrame(df)
def _dataframe_set_geometry(self, col, drop=False, inplace=False, crs=None):
......
......@@ -694,3 +694,23 @@ def test_buffer_single_multipolygon():
equal_geometries(result, expected)
result = arr.buffer(np.array([1]))
equal_geometries(result, expected)
def test_astype_multipolygon():
# https://github.com/geopandas/geopandas/issues/1145
multi_poly = shapely.geometry.MultiPolygon(
[shapely.geometry.box(0, 0, 1, 1), shapely.geometry.box(3, 3, 4, 4)]
)
arr = from_shapely([multi_poly])
result = arr.astype(str)
assert isinstance(result[0], str)
assert result[0] == multi_poly.wkt
# astype(object) does not convert to string
result = arr.astype(object)
assert isinstance(result[0], shapely.geometry.base.BaseGeometry)
# astype(np_dtype) honors the dtype
result = arr.astype(np.dtype("U10"))
assert result.dtype == np.dtype("U10")
assert result[0] == multi_poly.wkt[:10]
......@@ -161,18 +161,35 @@ def test_astype(s, df):
assert s.astype(str)[0] == "POINT (0 0)"
res = s.astype(object)
assert isinstance(res, pd.Series) and not isinstance(res, GeoSeries)
assert res.dtype == object
df = df.rename_geometry("geom_list")
# check whether returned object is a geodataframe
df = df.astype({"value1": float})
assert isinstance(df, GeoDataFrame)
res = df.astype({"value1": float})
assert isinstance(res, GeoDataFrame)
# check whether returned object is a datafrane
df = df.astype(str)
assert isinstance(df, pd.DataFrame)
res = df.astype(str)
assert isinstance(res, pd.DataFrame) and not isinstance(res, GeoDataFrame)
res = df.astype({"geom_list": str})
assert isinstance(res, pd.DataFrame) and not isinstance(res, GeoDataFrame)
df = df.astype({"geom_list": str})
assert isinstance(df, pd.DataFrame)
res = df.astype(object)
assert isinstance(res, pd.DataFrame) and not isinstance(res, GeoDataFrame)
assert res["geom_list"].dtype == object
def test_astype_invalid_geodataframe():
# https://github.com/geopandas/geopandas/issues/1144
# a GeoDataFrame without geometry column should not error in astype
df = GeoDataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
res = df.astype(object)
assert isinstance(res, pd.DataFrame) and not isinstance(res, GeoDataFrame)
assert res["a"].dtype == object
def test_to_csv(df):
......@@ -238,6 +255,11 @@ def test_fillna(s):
res = s2.fillna(Point(1, 1))
assert_geoseries_equal(res, s)
# allow np.nan although this does not change anything
# https://github.com/geopandas/geopandas/issues/1149
res = s2.fillna(np.nan)
assert_geoseries_equal(res, s2)
def test_dropna():
s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
......