We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BUG: TypeError exception shows the type of the wrong variable
https://github.com/geopandas/geopandas/blob/b366d890c35d68a52f7f608e47f00b89eaa85850/geopandas/tools/clip.py#L130

This should reference 'mask' instead of 'gdf'.

--- 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/tools/clip.py`
Content:
```
1 """
2 geopandas.clip
3 ==============
4 
5 A module to clip vector data using GeoPandas.
6 
7 """
8 import warnings
9 
10 import numpy as np
11 import pandas as pd
12 
13 from shapely.geometry import Polygon, MultiPolygon
14 
15 from geopandas import GeoDataFrame, GeoSeries
16 from geopandas.array import _check_crs, _crs_mismatch_warn
17 
18 
19 def _clip_points(gdf, poly):
20     """Clip point geometry to the polygon extent.
21 
22     Clip an input point GeoDataFrame to the polygon extent of the poly
23     parameter. Points that intersect the poly geometry are extracted with
24     associated attributes and returned.
25 
26     Parameters
27     ----------
28     gdf : GeoDataFrame, GeoSeries
29         Composed of point geometry that will be clipped to the poly.
30 
31     poly : (Multi)Polygon
32         Reference geometry used to spatially clip the data.
33 
34     Returns
35     -------
36     GeoDataFrame
37         The returned GeoDataFrame is a subset of gdf that intersects
38         with poly.
39     """
40     return gdf.iloc[gdf.sindex.query(poly, predicate="intersects")]
41 
42 
43 def _clip_line_poly(gdf, poly):
44     """Clip line and polygon geometry to the polygon extent.
45 
46     Clip an input line or polygon to the polygon extent of the poly
47     parameter. Parts of Lines or Polygons that intersect the poly geometry are
48     extracted with associated attributes and returned.
49 
50     Parameters
51     ----------
52     gdf : GeoDataFrame, GeoSeries
53         Line or polygon geometry that is clipped to poly.
54 
55     poly : (Multi)Polygon
56         Reference polygon for clipping.
57 
58     Returns
59     -------
60     GeoDataFrame
61         The returned GeoDataFrame is a clipped subset of gdf
62         that intersects with poly.
63     """
64     gdf_sub = gdf.iloc[gdf.sindex.query(poly, predicate="intersects")]
65 
66     # Clip the data with the polygon
67     if isinstance(gdf_sub, GeoDataFrame):
68         clipped = gdf_sub.copy()
69         clipped[gdf.geometry.name] = gdf_sub.intersection(poly)
70     else:
71         # GeoSeries
72         clipped = gdf_sub.intersection(poly)
73 
74     return clipped
75 
76 
77 def clip(gdf, mask, keep_geom_type=False):
78     """Clip points, lines, or polygon geometries to the mask extent.
79 
80     Both layers must be in the same Coordinate Reference System (CRS).
81     The `gdf` will be clipped to the full extent of the clip object.
82 
83     If there are multiple polygons in mask, data from `gdf` will be
84     clipped to the total boundary of all polygons in mask.
85 
86     Parameters
87     ----------
88     gdf : GeoDataFrame or GeoSeries
89         Vector layer (point, line, polygon) to be clipped to mask.
90     mask : GeoDataFrame, GeoSeries, (Multi)Polygon
91         Polygon vector layer used to clip `gdf`.
92         The mask's geometry is dissolved into one geometric feature
93         and intersected with `gdf`.
94     keep_geom_type : boolean, default False
95         If True, return only geometries of original type in case of intersection
96         resulting in multiple geometry types or GeometryCollections.
97         If False, return all resulting geometries (potentially mixed-types).
98 
99     Returns
100     -------
101     GeoDataFrame or GeoSeries
102          Vector data (points, lines, polygons) from `gdf` clipped to
103          polygon boundary from mask.
104 
105     Examples
106     --------
107     Clip points (global cities) with a polygon (the South American continent):
108 
109     >>> import geopandas
110     >>> path =
111     >>> world = geopandas.read_file(
112     ...     geopandas.datasets.get_path('naturalearth_lowres'))
113     >>> south_america = world[world['continent'] == "South America"]
114     >>> capitals = geopandas.read_file(
115     ...     geopandas.datasets.get_path('naturalearth_cities'))
116     >>> capitals.shape
117     (202, 2)
118     >>> sa_capitals = geopandas.clip(capitals, south_america)
119     >>> sa_capitals.shape
120     (12, 2)
121     """
122     if not isinstance(gdf, (GeoDataFrame, GeoSeries)):
123         raise TypeError(
124             "'gdf' should be GeoDataFrame or GeoSeries, got {}".format(type(gdf))
125         )
126 
127     if not isinstance(mask, (GeoDataFrame, GeoSeries, Polygon, MultiPolygon)):
128         raise TypeError(
129             "'mask' should be GeoDataFrame, GeoSeries or"
130             "(Multi)Polygon, got {}".format(type(gdf))
131         )
132 
133     if isinstance(mask, (GeoDataFrame, GeoSeries)):
134         if not _check_crs(gdf, mask):
135             _crs_mismatch_warn(gdf, mask, stacklevel=3)
136 
137     if isinstance(mask, (GeoDataFrame, GeoSeries)):
138         box_mask = mask.total_bounds
139     else:
140         box_mask = mask.bounds
141     box_gdf = gdf.total_bounds
142     if not (
143         ((box_mask[0] <= box_gdf[2]) and (box_gdf[0] <= box_mask[2]))
144         and ((box_mask[1] <= box_gdf[3]) and (box_gdf[1] <= box_mask[3]))
145     ):
146         return gdf.iloc[:0]
147 
148     if isinstance(mask, (GeoDataFrame, GeoSeries)):
149         poly = mask.geometry.unary_union
150     else:
151         poly = mask
152 
153     geom_types = gdf.geometry.type
154     poly_idx = np.asarray((geom_types == "Polygon") | (geom_types == "MultiPolygon"))
155     line_idx = np.asarray(
156         (geom_types == "LineString")
157         | (geom_types == "LinearRing")
158         | (geom_types == "MultiLineString")
159     )
160     point_idx = np.asarray((geom_types == "Point") | (geom_types == "MultiPoint"))
161     geomcoll_idx = np.asarray((geom_types == "GeometryCollection"))
162 
163     if point_idx.any():
164         point_gdf = _clip_points(gdf[point_idx], poly)
165     else:
166         point_gdf = None
167 
168     if poly_idx.any():
169         poly_gdf = _clip_line_poly(gdf[poly_idx], poly)
170     else:
171         poly_gdf = None
172 
173     if line_idx.any():
174         line_gdf = _clip_line_poly(gdf[line_idx], poly)
175     else:
176         line_gdf = None
177 
178     if geomcoll_idx.any():
179         geomcoll_gdf = _clip_line_poly(gdf[geomcoll_idx], poly)
180     else:
181         geomcoll_gdf = None
182 
183     order = pd.Series(range(len(gdf)), index=gdf.index)
184     concat = pd.concat([point_gdf, line_gdf, poly_gdf, geomcoll_gdf])
185 
186     if keep_geom_type:
187         geomcoll_concat = (concat.geom_type == "GeometryCollection").any()
188         geomcoll_orig = geomcoll_idx.any()
189 
190         new_collection = geomcoll_concat and not geomcoll_orig
191 
192         if geomcoll_orig:
193             warnings.warn(
194                 "keep_geom_type can not be called on a "
195                 "GeoDataFrame with GeometryCollection."
196             )
197         else:
198             polys = ["Polygon", "MultiPolygon"]
199             lines = ["LineString", "MultiLineString", "LinearRing"]
200             points = ["Point", "MultiPoint"]
201 
202             # Check that the gdf for multiple geom types (points, lines and/or polys)
203             orig_types_total = sum(
204                 [
205                     gdf.geom_type.isin(polys).any(),
206                     gdf.geom_type.isin(lines).any(),
207                     gdf.geom_type.isin(points).any(),
208                 ]
209             )
210 
211             # Check how many geometry types are in the clipped GeoDataFrame
212             clip_types_total = sum(
213                 [
214                     concat.geom_type.isin(polys).any(),
215                     concat.geom_type.isin(lines).any(),
216                     concat.geom_type.isin(points).any(),
217                 ]
218             )
219 
220             # Check there aren't any new geom types in the clipped GeoDataFrame
221             more_types = orig_types_total < clip_types_total
222 
223             if orig_types_total > 1:
224                 warnings.warn(
225                     "keep_geom_type can not be called on a mixed type GeoDataFrame."
226                 )
227             elif new_collection or more_types:
228                 orig_type = gdf.geom_type.iloc[0]
229                 if new_collection:
230                     concat = concat.explode()
231                 if orig_type in polys:
232                     concat = concat.loc[concat.geom_type.isin(polys)]
233                 elif orig_type in lines:
234                     concat = concat.loc[concat.geom_type.isin(lines)]
235 
236     # Return empty GeoDataFrame or GeoSeries if no shapes remain
237     if len(concat) == 0:
238         return gdf.iloc[:0]
239 
240     # Preserve the original order of the input
241     if isinstance(concat, GeoDataFrame):
242         concat["_order"] = order
243         return concat.sort_values(by="_order").drop(columns="_order")
244     else:
245         concat = GeoDataFrame(geometry=concat)
246         concat["_order"] = order
247         return concat.sort_values(by="_order").geometry
248
```
--- 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/tools/clip.py b/geopandas/tools/clip.py
--- a/geopandas/tools/clip.py
+++ b/geopandas/tools/clip.py
@@ -127,7 +127,7 @@
     if not isinstance(mask, (GeoDataFrame, GeoSeries, Polygon, MultiPolygon)):
         raise TypeError(
             "'mask' should be GeoDataFrame, GeoSeries or"
-            "(Multi)Polygon, got {}".format(type(gdf))
+            "(Multi)Polygon, got {}".format(type(mask))
         )
 
     if isinstance(mask, (GeoDataFrame, GeoSeries)):

{"golden_diff": "diff --git a/geopandas/tools/clip.py b/geopandas/tools/clip.py\n--- a/geopandas/tools/clip.py\n+++ b/geopandas/tools/clip.py\n@@ -127,7 +127,7 @@\n     if not isinstance(mask, (GeoDataFrame, GeoSeries, Polygon, MultiPolygon)):\n         raise TypeError(\n             \"'mask' should be GeoDataFrame, GeoSeries or\"\n-            \"(Multi)Polygon, got {}\".format(type(gdf))\n+            \"(Multi)Polygon, got {}\".format(type(mask))\n         )\n \n     if isinstance(mask, (GeoDataFrame, GeoSeries)):\n", "issue": "BUG: TypeError exception shows the type of the wrong variable\nhttps://github.com/geopandas/geopandas/blob/b366d890c35d68a52f7f608e47f00b89eaa85850/geopandas/tools/clip.py#L130\r\n\r\nThis should reference 'mask' instead of 'gdf'.\n", "before_files": [{"content": "\"\"\"\ngeopandas.clip\n==============\n\nA module to clip vector data using GeoPandas.\n\n\"\"\"\nimport warnings\n\nimport numpy as np\nimport pandas as pd\n\nfrom shapely.geometry import Polygon, MultiPolygon\n\nfrom geopandas import GeoDataFrame, GeoSeries\nfrom geopandas.array import _check_crs, _crs_mismatch_warn\n\n\ndef _clip_points(gdf, poly):\n    \"\"\"Clip point geometry to the polygon extent.\n\n    Clip an input point GeoDataFrame to the polygon extent of the poly\n    parameter. Points that intersect the poly geometry are extracted with\n    associated attributes and returned.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame, GeoSeries\n        Composed of point geometry that will be clipped to the poly.\n\n    poly : (Multi)Polygon\n        Reference geometry used to spatially clip the data.\n\n    Returns\n    -------\n    GeoDataFrame\n        The returned GeoDataFrame is a subset of gdf that intersects\n        with poly.\n    \"\"\"\n    return gdf.iloc[gdf.sindex.query(poly, predicate=\"intersects\")]\n\n\ndef _clip_line_poly(gdf, poly):\n    \"\"\"Clip line and polygon geometry to the polygon extent.\n\n    Clip an input line or polygon to the polygon extent of the poly\n    parameter. Parts of Lines or Polygons that intersect the poly geometry are\n    extracted with associated attributes and returned.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame, GeoSeries\n        Line or polygon geometry that is clipped to poly.\n\n    poly : (Multi)Polygon\n        Reference polygon for clipping.\n\n    Returns\n    -------\n    GeoDataFrame\n        The returned GeoDataFrame is a clipped subset of gdf\n        that intersects with poly.\n    \"\"\"\n    gdf_sub = gdf.iloc[gdf.sindex.query(poly, predicate=\"intersects\")]\n\n    # Clip the data with the polygon\n    if isinstance(gdf_sub, GeoDataFrame):\n        clipped = gdf_sub.copy()\n        clipped[gdf.geometry.name] = gdf_sub.intersection(poly)\n    else:\n        # GeoSeries\n        clipped = gdf_sub.intersection(poly)\n\n    return clipped\n\n\ndef clip(gdf, mask, keep_geom_type=False):\n    \"\"\"Clip points, lines, or polygon geometries to the mask extent.\n\n    Both layers must be in the same Coordinate Reference System (CRS).\n    The `gdf` will be clipped to the full extent of the clip object.\n\n    If there are multiple polygons in mask, data from `gdf` will be\n    clipped to the total boundary of all polygons in mask.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame or GeoSeries\n        Vector layer (point, line, polygon) to be clipped to mask.\n    mask : GeoDataFrame, GeoSeries, (Multi)Polygon\n        Polygon vector layer used to clip `gdf`.\n        The mask's geometry is dissolved into one geometric feature\n        and intersected with `gdf`.\n    keep_geom_type : boolean, default False\n        If True, return only geometries of original type in case of intersection\n        resulting in multiple geometry types or GeometryCollections.\n        If False, return all resulting geometries (potentially mixed-types).\n\n    Returns\n    -------\n    GeoDataFrame or GeoSeries\n         Vector data (points, lines, polygons) from `gdf` clipped to\n         polygon boundary from mask.\n\n    Examples\n    --------\n    Clip points (global cities) with a polygon (the South American continent):\n\n    >>> import geopandas\n    >>> path =\n    >>> world = geopandas.read_file(\n    ...     geopandas.datasets.get_path('naturalearth_lowres'))\n    >>> south_america = world[world['continent'] == \"South America\"]\n    >>> capitals = geopandas.read_file(\n    ...     geopandas.datasets.get_path('naturalearth_cities'))\n    >>> capitals.shape\n    (202, 2)\n    >>> sa_capitals = geopandas.clip(capitals, south_america)\n    >>> sa_capitals.shape\n    (12, 2)\n    \"\"\"\n    if not isinstance(gdf, (GeoDataFrame, GeoSeries)):\n        raise TypeError(\n            \"'gdf' should be GeoDataFrame or GeoSeries, got {}\".format(type(gdf))\n        )\n\n    if not isinstance(mask, (GeoDataFrame, GeoSeries, Polygon, MultiPolygon)):\n        raise TypeError(\n            \"'mask' should be GeoDataFrame, GeoSeries or\"\n            \"(Multi)Polygon, got {}\".format(type(gdf))\n        )\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        if not _check_crs(gdf, mask):\n            _crs_mismatch_warn(gdf, mask, stacklevel=3)\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        box_mask = mask.total_bounds\n    else:\n        box_mask = mask.bounds\n    box_gdf = gdf.total_bounds\n    if not (\n        ((box_mask[0] <= box_gdf[2]) and (box_gdf[0] <= box_mask[2]))\n        and ((box_mask[1] <= box_gdf[3]) and (box_gdf[1] <= box_mask[3]))\n    ):\n        return gdf.iloc[:0]\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        poly = mask.geometry.unary_union\n    else:\n        poly = mask\n\n    geom_types = gdf.geometry.type\n    poly_idx = np.asarray((geom_types == \"Polygon\") | (geom_types == \"MultiPolygon\"))\n    line_idx = np.asarray(\n        (geom_types == \"LineString\")\n        | (geom_types == \"LinearRing\")\n        | (geom_types == \"MultiLineString\")\n    )\n    point_idx = np.asarray((geom_types == \"Point\") | (geom_types == \"MultiPoint\"))\n    geomcoll_idx = np.asarray((geom_types == \"GeometryCollection\"))\n\n    if point_idx.any():\n        point_gdf = _clip_points(gdf[point_idx], poly)\n    else:\n        point_gdf = None\n\n    if poly_idx.any():\n        poly_gdf = _clip_line_poly(gdf[poly_idx], poly)\n    else:\n        poly_gdf = None\n\n    if line_idx.any():\n        line_gdf = _clip_line_poly(gdf[line_idx], poly)\n    else:\n        line_gdf = None\n\n    if geomcoll_idx.any():\n        geomcoll_gdf = _clip_line_poly(gdf[geomcoll_idx], poly)\n    else:\n        geomcoll_gdf = None\n\n    order = pd.Series(range(len(gdf)), index=gdf.index)\n    concat = pd.concat([point_gdf, line_gdf, poly_gdf, geomcoll_gdf])\n\n    if keep_geom_type:\n        geomcoll_concat = (concat.geom_type == \"GeometryCollection\").any()\n        geomcoll_orig = geomcoll_idx.any()\n\n        new_collection = geomcoll_concat and not geomcoll_orig\n\n        if geomcoll_orig:\n            warnings.warn(\n                \"keep_geom_type can not be called on a \"\n                \"GeoDataFrame with GeometryCollection.\"\n            )\n        else:\n            polys = [\"Polygon\", \"MultiPolygon\"]\n            lines = [\"LineString\", \"MultiLineString\", \"LinearRing\"]\n            points = [\"Point\", \"MultiPoint\"]\n\n            # Check that the gdf for multiple geom types (points, lines and/or polys)\n            orig_types_total = sum(\n                [\n                    gdf.geom_type.isin(polys).any(),\n                    gdf.geom_type.isin(lines).any(),\n                    gdf.geom_type.isin(points).any(),\n                ]\n            )\n\n            # Check how many geometry types are in the clipped GeoDataFrame\n            clip_types_total = sum(\n                [\n                    concat.geom_type.isin(polys).any(),\n                    concat.geom_type.isin(lines).any(),\n                    concat.geom_type.isin(points).any(),\n                ]\n            )\n\n            # Check there aren't any new geom types in the clipped GeoDataFrame\n            more_types = orig_types_total < clip_types_total\n\n            if orig_types_total > 1:\n                warnings.warn(\n                    \"keep_geom_type can not be called on a mixed type GeoDataFrame.\"\n                )\n            elif new_collection or more_types:\n                orig_type = gdf.geom_type.iloc[0]\n                if new_collection:\n                    concat = concat.explode()\n                if orig_type in polys:\n                    concat = concat.loc[concat.geom_type.isin(polys)]\n                elif orig_type in lines:\n                    concat = concat.loc[concat.geom_type.isin(lines)]\n\n    # Return empty GeoDataFrame or GeoSeries if no shapes remain\n    if len(concat) == 0:\n        return gdf.iloc[:0]\n\n    # Preserve the original order of the input\n    if isinstance(concat, GeoDataFrame):\n        concat[\"_order\"] = order\n        return concat.sort_values(by=\"_order\").drop(columns=\"_order\")\n    else:\n        concat = GeoDataFrame(geometry=concat)\n        concat[\"_order\"] = order\n        return concat.sort_values(by=\"_order\").geometry\n", "path": "geopandas/tools/clip.py"}], "after_files": [{"content": "\"\"\"\ngeopandas.clip\n==============\n\nA module to clip vector data using GeoPandas.\n\n\"\"\"\nimport warnings\n\nimport numpy as np\nimport pandas as pd\n\nfrom shapely.geometry import Polygon, MultiPolygon\n\nfrom geopandas import GeoDataFrame, GeoSeries\nfrom geopandas.array import _check_crs, _crs_mismatch_warn\n\n\ndef _clip_points(gdf, poly):\n    \"\"\"Clip point geometry to the polygon extent.\n\n    Clip an input point GeoDataFrame to the polygon extent of the poly\n    parameter. Points that intersect the poly geometry are extracted with\n    associated attributes and returned.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame, GeoSeries\n        Composed of point geometry that will be clipped to the poly.\n\n    poly : (Multi)Polygon\n        Reference geometry used to spatially clip the data.\n\n    Returns\n    -------\n    GeoDataFrame\n        The returned GeoDataFrame is a subset of gdf that intersects\n        with poly.\n    \"\"\"\n    return gdf.iloc[gdf.sindex.query(poly, predicate=\"intersects\")]\n\n\ndef _clip_line_poly(gdf, poly):\n    \"\"\"Clip line and polygon geometry to the polygon extent.\n\n    Clip an input line or polygon to the polygon extent of the poly\n    parameter. Parts of Lines or Polygons that intersect the poly geometry are\n    extracted with associated attributes and returned.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame, GeoSeries\n        Line or polygon geometry that is clipped to poly.\n\n    poly : (Multi)Polygon\n        Reference polygon for clipping.\n\n    Returns\n    -------\n    GeoDataFrame\n        The returned GeoDataFrame is a clipped subset of gdf\n        that intersects with poly.\n    \"\"\"\n    gdf_sub = gdf.iloc[gdf.sindex.query(poly, predicate=\"intersects\")]\n\n    # Clip the data with the polygon\n    if isinstance(gdf_sub, GeoDataFrame):\n        clipped = gdf_sub.copy()\n        clipped[gdf.geometry.name] = gdf_sub.intersection(poly)\n    else:\n        # GeoSeries\n        clipped = gdf_sub.intersection(poly)\n\n    return clipped\n\n\ndef clip(gdf, mask, keep_geom_type=False):\n    \"\"\"Clip points, lines, or polygon geometries to the mask extent.\n\n    Both layers must be in the same Coordinate Reference System (CRS).\n    The `gdf` will be clipped to the full extent of the clip object.\n\n    If there are multiple polygons in mask, data from `gdf` will be\n    clipped to the total boundary of all polygons in mask.\n\n    Parameters\n    ----------\n    gdf : GeoDataFrame or GeoSeries\n        Vector layer (point, line, polygon) to be clipped to mask.\n    mask : GeoDataFrame, GeoSeries, (Multi)Polygon\n        Polygon vector layer used to clip `gdf`.\n        The mask's geometry is dissolved into one geometric feature\n        and intersected with `gdf`.\n    keep_geom_type : boolean, default False\n        If True, return only geometries of original type in case of intersection\n        resulting in multiple geometry types or GeometryCollections.\n        If False, return all resulting geometries (potentially mixed-types).\n\n    Returns\n    -------\n    GeoDataFrame or GeoSeries\n         Vector data (points, lines, polygons) from `gdf` clipped to\n         polygon boundary from mask.\n\n    Examples\n    --------\n    Clip points (global cities) with a polygon (the South American continent):\n\n    >>> import geopandas\n    >>> path =\n    >>> world = geopandas.read_file(\n    ...     geopandas.datasets.get_path('naturalearth_lowres'))\n    >>> south_america = world[world['continent'] == \"South America\"]\n    >>> capitals = geopandas.read_file(\n    ...     geopandas.datasets.get_path('naturalearth_cities'))\n    >>> capitals.shape\n    (202, 2)\n    >>> sa_capitals = geopandas.clip(capitals, south_america)\n    >>> sa_capitals.shape\n    (12, 2)\n    \"\"\"\n    if not isinstance(gdf, (GeoDataFrame, GeoSeries)):\n        raise TypeError(\n            \"'gdf' should be GeoDataFrame or GeoSeries, got {}\".format(type(gdf))\n        )\n\n    if not isinstance(mask, (GeoDataFrame, GeoSeries, Polygon, MultiPolygon)):\n        raise TypeError(\n            \"'mask' should be GeoDataFrame, GeoSeries or\"\n            \"(Multi)Polygon, got {}\".format(type(mask))\n        )\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        if not _check_crs(gdf, mask):\n            _crs_mismatch_warn(gdf, mask, stacklevel=3)\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        box_mask = mask.total_bounds\n    else:\n        box_mask = mask.bounds\n    box_gdf = gdf.total_bounds\n    if not (\n        ((box_mask[0] <= box_gdf[2]) and (box_gdf[0] <= box_mask[2]))\n        and ((box_mask[1] <= box_gdf[3]) and (box_gdf[1] <= box_mask[3]))\n    ):\n        return gdf.iloc[:0]\n\n    if isinstance(mask, (GeoDataFrame, GeoSeries)):\n        poly = mask.geometry.unary_union\n    else:\n        poly = mask\n\n    geom_types = gdf.geometry.type\n    poly_idx = np.asarray((geom_types == \"Polygon\") | (geom_types == \"MultiPolygon\"))\n    line_idx = np.asarray(\n        (geom_types == \"LineString\")\n        | (geom_types == \"LinearRing\")\n        | (geom_types == \"MultiLineString\")\n    )\n    point_idx = np.asarray((geom_types == \"Point\") | (geom_types == \"MultiPoint\"))\n    geomcoll_idx = np.asarray((geom_types == \"GeometryCollection\"))\n\n    if point_idx.any():\n        point_gdf = _clip_points(gdf[point_idx], poly)\n    else:\n        point_gdf = None\n\n    if poly_idx.any():\n        poly_gdf = _clip_line_poly(gdf[poly_idx], poly)\n    else:\n        poly_gdf = None\n\n    if line_idx.any():\n        line_gdf = _clip_line_poly(gdf[line_idx], poly)\n    else:\n        line_gdf = None\n\n    if geomcoll_idx.any():\n        geomcoll_gdf = _clip_line_poly(gdf[geomcoll_idx], poly)\n    else:\n        geomcoll_gdf = None\n\n    order = pd.Series(range(len(gdf)), index=gdf.index)\n    concat = pd.concat([point_gdf, line_gdf, poly_gdf, geomcoll_gdf])\n\n    if keep_geom_type:\n        geomcoll_concat = (concat.geom_type == \"GeometryCollection\").any()\n        geomcoll_orig = geomcoll_idx.any()\n\n        new_collection = geomcoll_concat and not geomcoll_orig\n\n        if geomcoll_orig:\n            warnings.warn(\n                \"keep_geom_type can not be called on a \"\n                \"GeoDataFrame with GeometryCollection.\"\n            )\n        else:\n            polys = [\"Polygon\", \"MultiPolygon\"]\n            lines = [\"LineString\", \"MultiLineString\", \"LinearRing\"]\n            points = [\"Point\", \"MultiPoint\"]\n\n            # Check that the gdf for multiple geom types (points, lines and/or polys)\n            orig_types_total = sum(\n                [\n                    gdf.geom_type.isin(polys).any(),\n                    gdf.geom_type.isin(lines).any(),\n                    gdf.geom_type.isin(points).any(),\n                ]\n            )\n\n            # Check how many geometry types are in the clipped GeoDataFrame\n            clip_types_total = sum(\n                [\n                    concat.geom_type.isin(polys).any(),\n                    concat.geom_type.isin(lines).any(),\n                    concat.geom_type.isin(points).any(),\n                ]\n            )\n\n            # Check there aren't any new geom types in the clipped GeoDataFrame\n            more_types = orig_types_total < clip_types_total\n\n            if orig_types_total > 1:\n                warnings.warn(\n                    \"keep_geom_type can not be called on a mixed type GeoDataFrame.\"\n                )\n            elif new_collection or more_types:\n                orig_type = gdf.geom_type.iloc[0]\n                if new_collection:\n                    concat = concat.explode()\n                if orig_type in polys:\n                    concat = concat.loc[concat.geom_type.isin(polys)]\n                elif orig_type in lines:\n                    concat = concat.loc[concat.geom_type.isin(lines)]\n\n    # Return empty GeoDataFrame or GeoSeries if no shapes remain\n    if len(concat) == 0:\n        return gdf.iloc[:0]\n\n    # Preserve the original order of the input\n    if isinstance(concat, GeoDataFrame):\n        concat[\"_order\"] = order\n        return concat.sort_values(by=\"_order\").drop(columns=\"_order\")\n    else:\n        concat = GeoDataFrame(geometry=concat)\n        concat[\"_order\"] = order\n        return concat.sort_values(by=\"_order\").geometry\n", "path": "geopandas/tools/clip.py"}]}