We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BUG/COMPAT: missing values handling / fillna no longer working with shapely 1.6
See https://github.com/Toblerity/Shapely/issues/510 for more detailed exploration of the problem

Temporarily pinned our CI to older shapely version (but kept one with the latest shapely in the allowed failures section) in https://github.com/geopandas/geopandas/pull/508

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `geopandas/geoseries.py`
Content:
```
1 from functools import partial
2 import json
3 from warnings import warn
4 
5 import numpy as np
6 from pandas import Series, DataFrame
7 
8 import pyproj
9 from shapely.geometry import shape, Polygon, Point
10 from shapely.geometry.collection import GeometryCollection
11 from shapely.geometry.base import BaseGeometry
12 from shapely.ops import transform
13 
14 from geopandas.plotting import plot_series
15 from geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer
16 
17 
18 def _is_empty(x):
19     try:
20         return x.is_empty
21     except:
22         return False
23 
24 
25 class GeoSeries(GeoPandasBase, Series):
26     """A Series object designed to store shapely geometry objects."""
27     _metadata = ['name', 'crs']
28 
29     def __new__(cls, *args, **kwargs):
30         kwargs.pop('crs', None)
31         arr = Series.__new__(cls)
32         if type(arr) is GeoSeries:
33             return arr
34         else:
35             return arr.view(GeoSeries)
36 
37     def __init__(self, *args, **kwargs):
38         # fix problem for scalar geometries passed
39         if len(args) == 1 and isinstance(args[0], BaseGeometry):
40             args = ([args[0]],)
41 
42         crs = kwargs.pop('crs', None)
43 
44         super(GeoSeries, self).__init__(*args, **kwargs)
45         self.crs = crs
46         self._invalidate_sindex()
47 
48     def append(self, *args, **kwargs):
49         return self._wrapped_pandas_method('append', *args, **kwargs)
50 
51     @property
52     def geometry(self):
53         return self
54 
55     @property
56     def x(self):
57         """Return the x location of point geometries in a GeoSeries"""
58         if (self.geom_type == "Point").all():
59             return _series_unary_op(self, 'x', null_value=np.nan)
60         else:
61             message = "x attribute access only provided for Point geometries"
62             raise ValueError(message)
63 
64     @property
65     def y(self):
66         """Return the y location of point geometries in a GeoSeries"""
67         if (self.geom_type == "Point").all():
68             return _series_unary_op(self, 'y', null_value=np.nan)
69         else:
70             message = "y attribute access only provided for Point geometries"
71             raise ValueError(message)
72 
73     @classmethod
74     def from_file(cls, filename, **kwargs):
75         """
76         Alternate constructor to create a GeoSeries from a file
77 
78         Parameters
79         ----------
80 
81         filename : str
82             File path or file handle to read from. Depending on which kwargs
83             are included, the content of filename may vary, see:
84             http://toblerity.github.io/fiona/README.html#usage
85             for usage details.
86         kwargs : key-word arguments
87             These arguments are passed to fiona.open, and can be used to
88             access multi-layer data, data stored within archives (zip files),
89             etc.
90 
91         """
92         import fiona
93         geoms = []
94         with fiona.open(filename, **kwargs) as f:
95             crs = f.crs
96             for rec in f:
97                 geoms.append(shape(rec['geometry']))
98         g = GeoSeries(geoms)
99         g.crs = crs
100         return g
101 
102     @property
103     def __geo_interface__(self):
104         """Returns a GeoSeries as a python feature collection
105         """
106         from geopandas import GeoDataFrame
107         return GeoDataFrame({'geometry': self}).__geo_interface__
108 
109     def to_file(self, filename, driver="ESRI Shapefile", **kwargs):
110         from geopandas import GeoDataFrame
111         data = GeoDataFrame({"geometry": self,
112                           "id":self.index.values},
113                           index=self.index)
114         data.crs = self.crs
115         data.to_file(filename, driver, **kwargs)
116 
117     #
118     # Implement pandas methods
119     #
120 
121     @property
122     def _constructor(self):
123         return GeoSeries
124 
125     def _wrapped_pandas_method(self, mtd, *args, **kwargs):
126         """Wrap a generic pandas method to ensure it returns a GeoSeries"""
127         val = getattr(super(GeoSeries, self), mtd)(*args, **kwargs)
128         if type(val) == Series:
129             val.__class__ = GeoSeries
130             val.crs = self.crs
131             val._invalidate_sindex()
132         return val
133 
134     def __getitem__(self, key):
135         return self._wrapped_pandas_method('__getitem__', key)
136 
137     def sort_index(self, *args, **kwargs):
138         return self._wrapped_pandas_method('sort_index', *args, **kwargs)
139 
140     def take(self, *args, **kwargs):
141         return self._wrapped_pandas_method('take', *args, **kwargs)
142 
143     def select(self, *args, **kwargs):
144         return self._wrapped_pandas_method('select', *args, **kwargs)
145 
146     @property
147     def _can_hold_na(self):
148         return False
149 
150     def __finalize__(self, other, method=None, **kwargs):
151         """ propagate metadata from other to self """
152         # NOTE: backported from pandas master (upcoming v0.13)
153         for name in self._metadata:
154             object.__setattr__(self, name, getattr(other, name, None))
155         return self
156 
157     def copy(self, order='C'):
158         """
159         Make a copy of this GeoSeries object
160 
161         Parameters
162         ----------
163         deep : boolean, default True
164             Make a deep copy, i.e. also copy data
165 
166         Returns
167         -------
168         copy : GeoSeries
169         """
170         # FIXME: this will likely be unnecessary in pandas >= 0.13
171         return GeoSeries(self.values.copy(order), index=self.index,
172                       name=self.name).__finalize__(self)
173 
174     def isnull(self):
175         """Null values in a GeoSeries are represented by empty geometric objects"""
176         non_geo_null = super(GeoSeries, self).isnull()
177         val = self.apply(_is_empty)
178         return np.logical_or(non_geo_null, val)
179 
180     def fillna(self, value=None, method=None, inplace=False,
181                **kwargs):
182         """Fill NA/NaN values with a geometry (empty polygon by default).
183 
184         "method" is currently not implemented for pandas <= 0.12.
185         """
186         if value is None:
187             value = Point()
188         return super(GeoSeries, self).fillna(value=value, method=method,
189                                              inplace=inplace, **kwargs)
190 
191     def align(self, other, join='outer', level=None, copy=True,
192               fill_value=None, **kwargs):
193         if fill_value is None:
194             fill_value = Point()
195         left, right = super(GeoSeries, self).align(other, join=join,
196                                                    level=level, copy=copy,
197                                                    fill_value=fill_value,
198                                                    **kwargs)
199         if isinstance(other, GeoSeries):
200             return GeoSeries(left), GeoSeries(right)
201         else: # It is probably a Series, let's keep it that way
202             return GeoSeries(left), right
203 
204 
205     def __contains__(self, other):
206         """Allow tests of the form "geom in s"
207 
208         Tests whether a GeoSeries contains a geometry.
209 
210         Note: This is not the same as the geometric method "contains".
211         """
212         if isinstance(other, BaseGeometry):
213             return np.any(self.geom_equals(other))
214         else:
215             return False
216 
217     def plot(self, *args, **kwargs):
218         return plot_series(self, *args, **kwargs)
219 
220     plot.__doc__ = plot_series.__doc__
221 
222     #
223     # Additional methods
224     #
225 
226     def to_crs(self, crs=None, epsg=None):
227         """Transform geometries to a new coordinate reference system
228 
229         This method will transform all points in all objects.  It has
230         no notion or projecting entire geometries.  All segments
231         joining points are assumed to be lines in the current
232         projection, not geodesics.  Objects crossing the dateline (or
233         other projection boundary) will have undesirable behavior.
234 
235         `to_crs` passes the `crs` argument to the `Proj` function from the
236         `pyproj` library (with the option `preserve_units=True`). It can
237         therefore accept proj4 projections in any format
238         supported by `Proj`, including dictionaries, or proj4 strings.
239 
240         """
241         from fiona.crs import from_epsg
242         if self.crs is None:
243             raise ValueError('Cannot transform naive geometries.  '
244                              'Please set a crs on the object first.')
245         if crs is None:
246             try:
247                 crs = from_epsg(epsg)
248             except TypeError:
249                 raise TypeError('Must set either crs or epsg for output.')
250         proj_in = pyproj.Proj(self.crs, preserve_units=True)
251         proj_out = pyproj.Proj(crs, preserve_units=True)
252         project = partial(pyproj.transform, proj_in, proj_out)
253         result = self.apply(lambda geom: transform(project, geom))
254         result.__class__ = GeoSeries
255         result.crs = crs
256         result._invalidate_sindex()
257         return result
258 
259     def to_json(self, **kwargs):
260         """
261         Returns a GeoJSON string representation of the GeoSeries.
262 
263         Parameters
264         ----------
265         *kwargs* that will be passed to json.dumps().
266         """
267         return json.dumps(self.__geo_interface__, **kwargs)
268 
269     #
270     # Implement standard operators for GeoSeries
271     #
272 
273     def __xor__(self, other):
274         """Implement ^ operator as for builtin set type"""
275         return self.symmetric_difference(other)
276 
277     def __or__(self, other):
278         """Implement | operator as for builtin set type"""
279         return self.union(other)
280 
281     def __and__(self, other):
282         """Implement & operator as for builtin set type"""
283         return self.intersection(other)
284 
285     def __sub__(self, other):
286         """Implement - operator as for builtin set type"""
287         return self.difference(other)
288 
289 GeoSeries._create_indexer('cx', _CoordinateIndexer)
290
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py
--- a/geopandas/geoseries.py
+++ b/geopandas/geoseries.py
@@ -184,14 +184,14 @@
         "method" is currently not implemented for pandas <= 0.12.
         """
         if value is None:
-            value = Point()
+            value = BaseGeometry()
         return super(GeoSeries, self).fillna(value=value, method=method,
                                              inplace=inplace, **kwargs)
 
     def align(self, other, join='outer', level=None, copy=True,
               fill_value=None, **kwargs):
         if fill_value is None:
-            fill_value = Point()
+            fill_value = BaseGeometry()
         left, right = super(GeoSeries, self).align(other, join=join,
                                                    level=level, copy=copy,
                                                    fill_value=fill_value,

{"golden_diff": "diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py\n--- a/geopandas/geoseries.py\n+++ b/geopandas/geoseries.py\n@@ -184,14 +184,14 @@\n         \"method\" is currently not implemented for pandas <= 0.12.\n         \"\"\"\n         if value is None:\n-            value = Point()\n+            value = BaseGeometry()\n         return super(GeoSeries, self).fillna(value=value, method=method,\n                                              inplace=inplace, **kwargs)\n \n     def align(self, other, join='outer', level=None, copy=True,\n               fill_value=None, **kwargs):\n         if fill_value is None:\n-            fill_value = Point()\n+            fill_value = BaseGeometry()\n         left, right = super(GeoSeries, self).align(other, join=join,\n                                                    level=level, copy=copy,\n                                                    fill_value=fill_value,\n", "issue": "BUG/COMPAT: missing values handling / fillna no longer working with shapely 1.6\nSee https://github.com/Toblerity/Shapely/issues/510 for more detailed exploration of the problem\r\n\r\nTemporarily pinned our CI to older shapely version (but kept one with the latest shapely in the allowed failures section) in https://github.com/geopandas/geopandas/pull/508\n", "before_files": [{"content": "from functools import partial\nimport json\nfrom warnings import warn\n\nimport numpy as np\nfrom pandas import Series, DataFrame\n\nimport pyproj\nfrom shapely.geometry import shape, Polygon, Point\nfrom shapely.geometry.collection import GeometryCollection\nfrom shapely.geometry.base import BaseGeometry\nfrom shapely.ops import transform\n\nfrom geopandas.plotting import plot_series\nfrom geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer\n\n\ndef _is_empty(x):\n    try:\n        return x.is_empty\n    except:\n        return False\n\n\nclass GeoSeries(GeoPandasBase, Series):\n    \"\"\"A Series object designed to store shapely geometry objects.\"\"\"\n    _metadata = ['name', 'crs']\n\n    def __new__(cls, *args, **kwargs):\n        kwargs.pop('crs', None)\n        arr = Series.__new__(cls)\n        if type(arr) is GeoSeries:\n            return arr\n        else:\n            return arr.view(GeoSeries)\n\n    def __init__(self, *args, **kwargs):\n        # fix problem for scalar geometries passed\n        if len(args) == 1 and isinstance(args[0], BaseGeometry):\n            args = ([args[0]],)\n\n        crs = kwargs.pop('crs', None)\n\n        super(GeoSeries, self).__init__(*args, **kwargs)\n        self.crs = crs\n        self._invalidate_sindex()\n\n    def append(self, *args, **kwargs):\n        return self._wrapped_pandas_method('append', *args, **kwargs)\n\n    @property\n    def geometry(self):\n        return self\n\n    @property\n    def x(self):\n        \"\"\"Return the x location of point geometries in a GeoSeries\"\"\"\n        if (self.geom_type == \"Point\").all():\n            return _series_unary_op(self, 'x', null_value=np.nan)\n        else:\n            message = \"x attribute access only provided for Point geometries\"\n            raise ValueError(message)\n\n    @property\n    def y(self):\n        \"\"\"Return the y location of point geometries in a GeoSeries\"\"\"\n        if (self.geom_type == \"Point\").all():\n            return _series_unary_op(self, 'y', null_value=np.nan)\n        else:\n            message = \"y attribute access only provided for Point geometries\"\n            raise ValueError(message)\n\n    @classmethod\n    def from_file(cls, filename, **kwargs):\n        \"\"\"\n        Alternate constructor to create a GeoSeries from a file\n\n        Parameters\n        ----------\n\n        filename : str\n            File path or file handle to read from. Depending on which kwargs\n            are included, the content of filename may vary, see:\n            http://toblerity.github.io/fiona/README.html#usage\n            for usage details.\n        kwargs : key-word arguments\n            These arguments are passed to fiona.open, and can be used to\n            access multi-layer data, data stored within archives (zip files),\n            etc.\n\n        \"\"\"\n        import fiona\n        geoms = []\n        with fiona.open(filename, **kwargs) as f:\n            crs = f.crs\n            for rec in f:\n                geoms.append(shape(rec['geometry']))\n        g = GeoSeries(geoms)\n        g.crs = crs\n        return g\n\n    @property\n    def __geo_interface__(self):\n        \"\"\"Returns a GeoSeries as a python feature collection\n        \"\"\"\n        from geopandas import GeoDataFrame\n        return GeoDataFrame({'geometry': self}).__geo_interface__\n\n    def to_file(self, filename, driver=\"ESRI Shapefile\", **kwargs):\n        from geopandas import GeoDataFrame\n        data = GeoDataFrame({\"geometry\": self,\n                          \"id\":self.index.values},\n                          index=self.index)\n        data.crs = self.crs\n        data.to_file(filename, driver, **kwargs)\n\n    #\n    # Implement pandas methods\n    #\n\n    @property\n    def _constructor(self):\n        return GeoSeries\n\n    def _wrapped_pandas_method(self, mtd, *args, **kwargs):\n        \"\"\"Wrap a generic pandas method to ensure it returns a GeoSeries\"\"\"\n        val = getattr(super(GeoSeries, self), mtd)(*args, **kwargs)\n        if type(val) == Series:\n            val.__class__ = GeoSeries\n            val.crs = self.crs\n            val._invalidate_sindex()\n        return val\n\n    def __getitem__(self, key):\n        return self._wrapped_pandas_method('__getitem__', key)\n\n    def sort_index(self, *args, **kwargs):\n        return self._wrapped_pandas_method('sort_index', *args, **kwargs)\n\n    def take(self, *args, **kwargs):\n        return self._wrapped_pandas_method('take', *args, **kwargs)\n\n    def select(self, *args, **kwargs):\n        return self._wrapped_pandas_method('select', *args, **kwargs)\n\n    @property\n    def _can_hold_na(self):\n        return False\n\n    def __finalize__(self, other, method=None, **kwargs):\n        \"\"\" propagate metadata from other to self \"\"\"\n        # NOTE: backported from pandas master (upcoming v0.13)\n        for name in self._metadata:\n            object.__setattr__(self, name, getattr(other, name, None))\n        return self\n\n    def copy(self, order='C'):\n        \"\"\"\n        Make a copy of this GeoSeries object\n\n        Parameters\n        ----------\n        deep : boolean, default True\n            Make a deep copy, i.e. also copy data\n\n        Returns\n        -------\n        copy : GeoSeries\n        \"\"\"\n        # FIXME: this will likely be unnecessary in pandas >= 0.13\n        return GeoSeries(self.values.copy(order), index=self.index,\n                      name=self.name).__finalize__(self)\n\n    def isnull(self):\n        \"\"\"Null values in a GeoSeries are represented by empty geometric objects\"\"\"\n        non_geo_null = super(GeoSeries, self).isnull()\n        val = self.apply(_is_empty)\n        return np.logical_or(non_geo_null, val)\n\n    def fillna(self, value=None, method=None, inplace=False,\n               **kwargs):\n        \"\"\"Fill NA/NaN values with a geometry (empty polygon by default).\n\n        \"method\" is currently not implemented for pandas <= 0.12.\n        \"\"\"\n        if value is None:\n            value = Point()\n        return super(GeoSeries, self).fillna(value=value, method=method,\n                                             inplace=inplace, **kwargs)\n\n    def align(self, other, join='outer', level=None, copy=True,\n              fill_value=None, **kwargs):\n        if fill_value is None:\n            fill_value = Point()\n        left, right = super(GeoSeries, self).align(other, join=join,\n                                                   level=level, copy=copy,\n                                                   fill_value=fill_value,\n                                                   **kwargs)\n        if isinstance(other, GeoSeries):\n            return GeoSeries(left), GeoSeries(right)\n        else: # It is probably a Series, let's keep it that way\n            return GeoSeries(left), right\n\n\n    def __contains__(self, other):\n        \"\"\"Allow tests of the form \"geom in s\"\n\n        Tests whether a GeoSeries contains a geometry.\n\n        Note: This is not the same as the geometric method \"contains\".\n        \"\"\"\n        if isinstance(other, BaseGeometry):\n            return np.any(self.geom_equals(other))\n        else:\n            return False\n\n    def plot(self, *args, **kwargs):\n        return plot_series(self, *args, **kwargs)\n\n    plot.__doc__ = plot_series.__doc__\n\n    #\n    # Additional methods\n    #\n\n    def to_crs(self, crs=None, epsg=None):\n        \"\"\"Transform geometries to a new coordinate reference system\n\n        This method will transform all points in all objects.  It has\n        no notion or projecting entire geometries.  All segments\n        joining points are assumed to be lines in the current\n        projection, not geodesics.  Objects crossing the dateline (or\n        other projection boundary) will have undesirable behavior.\n\n        `to_crs` passes the `crs` argument to the `Proj` function from the\n        `pyproj` library (with the option `preserve_units=True`). It can\n        therefore accept proj4 projections in any format\n        supported by `Proj`, including dictionaries, or proj4 strings.\n\n        \"\"\"\n        from fiona.crs import from_epsg\n        if self.crs is None:\n            raise ValueError('Cannot transform naive geometries.  '\n                             'Please set a crs on the object first.')\n        if crs is None:\n            try:\n                crs = from_epsg(epsg)\n            except TypeError:\n                raise TypeError('Must set either crs or epsg for output.')\n        proj_in = pyproj.Proj(self.crs, preserve_units=True)\n        proj_out = pyproj.Proj(crs, preserve_units=True)\n        project = partial(pyproj.transform, proj_in, proj_out)\n        result = self.apply(lambda geom: transform(project, geom))\n        result.__class__ = GeoSeries\n        result.crs = crs\n        result._invalidate_sindex()\n        return result\n\n    def to_json(self, **kwargs):\n        \"\"\"\n        Returns a GeoJSON string representation of the GeoSeries.\n\n        Parameters\n        ----------\n        *kwargs* that will be passed to json.dumps().\n        \"\"\"\n        return json.dumps(self.__geo_interface__, **kwargs)\n\n    #\n    # Implement standard operators for GeoSeries\n    #\n\n    def __xor__(self, other):\n        \"\"\"Implement ^ operator as for builtin set type\"\"\"\n        return self.symmetric_difference(other)\n\n    def __or__(self, other):\n        \"\"\"Implement | operator as for builtin set type\"\"\"\n        return self.union(other)\n\n    def __and__(self, other):\n        \"\"\"Implement & operator as for builtin set type\"\"\"\n        return self.intersection(other)\n\n    def __sub__(self, other):\n        \"\"\"Implement - operator as for builtin set type\"\"\"\n        return self.difference(other)\n\nGeoSeries._create_indexer('cx', _CoordinateIndexer)\n", "path": "geopandas/geoseries.py"}], "after_files": [{"content": "from functools import partial\nimport json\nfrom warnings import warn\n\nimport numpy as np\nfrom pandas import Series, DataFrame\n\nimport pyproj\nfrom shapely.geometry import shape, Polygon, Point\nfrom shapely.geometry.collection import GeometryCollection\nfrom shapely.geometry.base import BaseGeometry\nfrom shapely.ops import transform\n\nfrom geopandas.plotting import plot_series\nfrom geopandas.base import GeoPandasBase, _series_unary_op, _CoordinateIndexer\n\n\ndef _is_empty(x):\n    try:\n        return x.is_empty\n    except:\n        return False\n\n\nclass GeoSeries(GeoPandasBase, Series):\n    \"\"\"A Series object designed to store shapely geometry objects.\"\"\"\n    _metadata = ['name', 'crs']\n\n    def __new__(cls, *args, **kwargs):\n        kwargs.pop('crs', None)\n        arr = Series.__new__(cls)\n        if type(arr) is GeoSeries:\n            return arr\n        else:\n            return arr.view(GeoSeries)\n\n    def __init__(self, *args, **kwargs):\n        # fix problem for scalar geometries passed\n        if len(args) == 1 and isinstance(args[0], BaseGeometry):\n            args = ([args[0]],)\n\n        crs = kwargs.pop('crs', None)\n\n        super(GeoSeries, self).__init__(*args, **kwargs)\n        self.crs = crs\n        self._invalidate_sindex()\n\n    def append(self, *args, **kwargs):\n        return self._wrapped_pandas_method('append', *args, **kwargs)\n\n    @property\n    def geometry(self):\n        return self\n\n    @property\n    def x(self):\n        \"\"\"Return the x location of point geometries in a GeoSeries\"\"\"\n        if (self.geom_type == \"Point\").all():\n            return _series_unary_op(self, 'x', null_value=np.nan)\n        else:\n            message = \"x attribute access only provided for Point geometries\"\n            raise ValueError(message)\n\n    @property\n    def y(self):\n        \"\"\"Return the y location of point geometries in a GeoSeries\"\"\"\n        if (self.geom_type == \"Point\").all():\n            return _series_unary_op(self, 'y', null_value=np.nan)\n        else:\n            message = \"y attribute access only provided for Point geometries\"\n            raise ValueError(message)\n\n    @classmethod\n    def from_file(cls, filename, **kwargs):\n        \"\"\"\n        Alternate constructor to create a GeoSeries from a file\n\n        Parameters\n        ----------\n\n        filename : str\n            File path or file handle to read from. Depending on which kwargs\n            are included, the content of filename may vary, see:\n            http://toblerity.github.io/fiona/README.html#usage\n            for usage details.\n        kwargs : key-word arguments\n            These arguments are passed to fiona.open, and can be used to\n            access multi-layer data, data stored within archives (zip files),\n            etc.\n\n        \"\"\"\n        import fiona\n        geoms = []\n        with fiona.open(filename, **kwargs) as f:\n            crs = f.crs\n            for rec in f:\n                geoms.append(shape(rec['geometry']))\n        g = GeoSeries(geoms)\n        g.crs = crs\n        return g\n\n    @property\n    def __geo_interface__(self):\n        \"\"\"Returns a GeoSeries as a python feature collection\n        \"\"\"\n        from geopandas import GeoDataFrame\n        return GeoDataFrame({'geometry': self}).__geo_interface__\n\n    def to_file(self, filename, driver=\"ESRI Shapefile\", **kwargs):\n        from geopandas import GeoDataFrame\n        data = GeoDataFrame({\"geometry\": self,\n                          \"id\":self.index.values},\n                          index=self.index)\n        data.crs = self.crs\n        data.to_file(filename, driver, **kwargs)\n\n    #\n    # Implement pandas methods\n    #\n\n    @property\n    def _constructor(self):\n        return GeoSeries\n\n    def _wrapped_pandas_method(self, mtd, *args, **kwargs):\n        \"\"\"Wrap a generic pandas method to ensure it returns a GeoSeries\"\"\"\n        val = getattr(super(GeoSeries, self), mtd)(*args, **kwargs)\n        if type(val) == Series:\n            val.__class__ = GeoSeries\n            val.crs = self.crs\n            val._invalidate_sindex()\n        return val\n\n    def __getitem__(self, key):\n        return self._wrapped_pandas_method('__getitem__', key)\n\n    def sort_index(self, *args, **kwargs):\n        return self._wrapped_pandas_method('sort_index', *args, **kwargs)\n\n    def take(self, *args, **kwargs):\n        return self._wrapped_pandas_method('take', *args, **kwargs)\n\n    def select(self, *args, **kwargs):\n        return self._wrapped_pandas_method('select', *args, **kwargs)\n\n    @property\n    def _can_hold_na(self):\n        return False\n\n    def __finalize__(self, other, method=None, **kwargs):\n        \"\"\" propagate metadata from other to self \"\"\"\n        # NOTE: backported from pandas master (upcoming v0.13)\n        for name in self._metadata:\n            object.__setattr__(self, name, getattr(other, name, None))\n        return self\n\n    def copy(self, order='C'):\n        \"\"\"\n        Make a copy of this GeoSeries object\n\n        Parameters\n        ----------\n        deep : boolean, default True\n            Make a deep copy, i.e. also copy data\n\n        Returns\n        -------\n        copy : GeoSeries\n        \"\"\"\n        # FIXME: this will likely be unnecessary in pandas >= 0.13\n        return GeoSeries(self.values.copy(order), index=self.index,\n                      name=self.name).__finalize__(self)\n\n    def isnull(self):\n        \"\"\"Null values in a GeoSeries are represented by empty geometric objects\"\"\"\n        non_geo_null = super(GeoSeries, self).isnull()\n        val = self.apply(_is_empty)\n        return np.logical_or(non_geo_null, val)\n\n    def fillna(self, value=None, method=None, inplace=False,\n               **kwargs):\n        \"\"\"Fill NA/NaN values with a geometry (empty polygon by default).\n\n        \"method\" is currently not implemented for pandas <= 0.12.\n        \"\"\"\n        if value is None:\n            value = BaseGeometry()\n        return super(GeoSeries, self).fillna(value=value, method=method,\n                                             inplace=inplace, **kwargs)\n\n    def align(self, other, join='outer', level=None, copy=True,\n              fill_value=None, **kwargs):\n        if fill_value is None:\n            fill_value = BaseGeometry()\n        left, right = super(GeoSeries, self).align(other, join=join,\n                                                   level=level, copy=copy,\n                                                   fill_value=fill_value,\n                                                   **kwargs)\n        if isinstance(other, GeoSeries):\n            return GeoSeries(left), GeoSeries(right)\n        else: # It is probably a Series, let's keep it that way\n            return GeoSeries(left), right\n\n\n    def __contains__(self, other):\n        \"\"\"Allow tests of the form \"geom in s\"\n\n        Tests whether a GeoSeries contains a geometry.\n\n        Note: This is not the same as the geometric method \"contains\".\n        \"\"\"\n        if isinstance(other, BaseGeometry):\n            return np.any(self.geom_equals(other))\n        else:\n            return False\n\n    def plot(self, *args, **kwargs):\n        return plot_series(self, *args, **kwargs)\n\n    plot.__doc__ = plot_series.__doc__\n\n    #\n    # Additional methods\n    #\n\n    def to_crs(self, crs=None, epsg=None):\n        \"\"\"Transform geometries to a new coordinate reference system\n\n        This method will transform all points in all objects.  It has\n        no notion or projecting entire geometries.  All segments\n        joining points are assumed to be lines in the current\n        projection, not geodesics.  Objects crossing the dateline (or\n        other projection boundary) will have undesirable behavior.\n\n        `to_crs` passes the `crs` argument to the `Proj` function from the\n        `pyproj` library (with the option `preserve_units=True`). It can\n        therefore accept proj4 projections in any format\n        supported by `Proj`, including dictionaries, or proj4 strings.\n\n        \"\"\"\n        from fiona.crs import from_epsg\n        if self.crs is None:\n            raise ValueError('Cannot transform naive geometries.  '\n                             'Please set a crs on the object first.')\n        if crs is None:\n            try:\n                crs = from_epsg(epsg)\n            except TypeError:\n                raise TypeError('Must set either crs or epsg for output.')\n        proj_in = pyproj.Proj(self.crs, preserve_units=True)\n        proj_out = pyproj.Proj(crs, preserve_units=True)\n        project = partial(pyproj.transform, proj_in, proj_out)\n        result = self.apply(lambda geom: transform(project, geom))\n        result.__class__ = GeoSeries\n        result.crs = crs\n        result._invalidate_sindex()\n        return result\n\n    def to_json(self, **kwargs):\n        \"\"\"\n        Returns a GeoJSON string representation of the GeoSeries.\n\n        Parameters\n        ----------\n        *kwargs* that will be passed to json.dumps().\n        \"\"\"\n        return json.dumps(self.__geo_interface__, **kwargs)\n\n    #\n    # Implement standard operators for GeoSeries\n    #\n\n    def __xor__(self, other):\n        \"\"\"Implement ^ operator as for builtin set type\"\"\"\n        return self.symmetric_difference(other)\n\n    def __or__(self, other):\n        \"\"\"Implement | operator as for builtin set type\"\"\"\n        return self.union(other)\n\n    def __and__(self, other):\n        \"\"\"Implement & operator as for builtin set type\"\"\"\n        return self.intersection(other)\n\n    def __sub__(self, other):\n        \"\"\"Implement - operator as for builtin set type\"\"\"\n        return self.difference(other)\n\nGeoSeries._create_indexer('cx', _CoordinateIndexer)\n", "path": "geopandas/geoseries.py"}]}