Repository: geopandas/geopandas

Issue:
fillna error with 0.6
When performing `fillna` with `numpy.nan` on the entire dataframe, I get this error in version 0.6:
```
~/miniconda/envs/geocube/lib/python3.6/site-packages/geopandas/array.py in fillna(self, value, method, limit)
    831         elif not isinstance(value, BaseGeometry):
    832             raise NotImplementedError(
--> 833                 "fillna currently only supports filling with a scalar geometry"
    834             )
    835 

NotImplementedError: fillna currently only supports filling with a scalar geometry
```

Is this expected? Future plans?

Discussion:
martinfleis: Can you make a tests for it? So we don't break it in the future again.
bnaul: done!
martinfleis: This one is nice to have, but I'd rather see `fillna(0)` on gdf where it 1) actually fills missing values, 2) raises `NotImplementedError` if there is a missing geometry value. To test the actual use cases, rather than the bare minimum.
bnaul: Thanks @martinfleis, that makes sense; pushed a new version that is a bit more comprehensive.

Patch:
diff --git a/geopandas/array.py b/geopandas/array.py
index a7bb9cc0..61b3dc0f 100644
--- a/geopandas/array.py
+++ b/geopandas/array.py
@@ -858,18 +858,17 @@ 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"
-            )
-
         mask = self.isna()
         new_values = self.copy()
 
         if mask.any():
             # fill with value
+            if _isna(value):
+                value = None
+            elif not isinstance(value, BaseGeometry):
+                raise NotImplementedError(
+                    "fillna currently only supports filling with a scalar geometry"
+                )
             new_values = new_values._fill(mask, value)
 
         return new_values


Test patch:
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
index 71cd1a80..5e553635 100644
--- a/geopandas/tests/test_pandas_methods.py
+++ b/geopandas/tests/test_pandas_methods.py
@@ -317,7 +317,7 @@ def test_select_dtypes(df):
 # Missing values
 
 
-def test_fillna(s):
+def test_fillna(s, df):
     s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
     res = s2.fillna(Point(1, 1))
     assert_geoseries_equal(res, s)
@@ -327,6 +327,21 @@ def test_fillna(s):
     res = s2.fillna(np.nan)
     assert_geoseries_equal(res, s2)
 
+    # raise exception if trying to fill missing geometry w/ non-geometry
+    df2 = df.copy()
+    df2["geometry"] = s2
+    res = df2.fillna(Point(1, 1))
+    assert_geodataframe_equal(res, df)
+    with pytest.raises(NotImplementedError):
+        df2.fillna(0)
+
+    # allow non-geometry fill value if there are no missing values
+    # https://github.com/geopandas/geopandas/issues/1149
+    df3 = df.copy()
+    df3.loc[0, "value1"] = np.nan
+    res = df3.fillna(0)
+    assert_geodataframe_equal(res.astype({"value1": "int64"}), df)
+
 
 def test_dropna():
     s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])