[Git][debian-gis-team/python-geopandas][upstream] New upstream version 0.6.1

Bas Couwenberg gitlab at salsa.debian.org
Sun Oct 13 07:48:23 BST 2019



Bas Couwenberg pushed to branch upstream at Debian GIS Project / python-geopandas


Commits:
07e41a87 by Bas Couwenberg at 2019-10-13T06:36:52Z
New upstream version 0.6.1
- - - - -


6 changed files:

- CHANGELOG.md
- geopandas/_version.py
- geopandas/array.py
- geopandas/geodataframe.py
- geopandas/tests/test_array.py
- geopandas/tests/test_pandas_methods.py


Changes:

=====================================
CHANGELOG.md
=====================================
@@ -1,6 +1,15 @@
 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)
 ----------------------------------
 


=====================================
geopandas/_version.py
=====================================
@@ -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
 


=====================================
geopandas/array.py
=====================================
@@ -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,7 +868,12 @@ class GeometryArray(ExtensionArray):
                 return self.copy()
             else:
                 return self
-        return np.array(self, dtype=dtype, copy=copy)
+        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):
         """


=====================================
geopandas/geodataframe.py
=====================================
@@ -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):


=====================================
geopandas/tests/test_array.py
=====================================
@@ -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]


=====================================
geopandas/tests/test_pandas_methods.py
=====================================
@@ -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)])



View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geopandas/commit/07e41a87570fad61da4913a3af761335bb48dbb1

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/python-geopandas/commit/07e41a87570fad61da4913a3af761335bb48dbb1
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20191013/690ede82/attachment-0001.html>


More information about the Pkg-grass-devel mailing list