We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TST: test_value_counts breaking against pandas latest
Recent CI builds on 38-dev.yaml are all failing due to geopandas/tests/test_pandas_methods.py::test_value_counts, which fails with the output:
```
______________________________ test_value_counts _______________________________
3536
[gw0] linux -- Python 3.8.12 /usr/share/miniconda3/envs/test/bin/python
3537

3538
    def test_value_counts():
3539
        # each object is considered unique
3540
        s = GeoSeries([Point(0, 0), Point(1, 1), Point(0, 0)])
3541
        res = s.value_counts()
3542
        with compat.ignore_shapely2_warnings():
3543
            exp = pd.Series([2, 1], index=[Point(0, 0), Point(1, 1)])
3544
>       assert_series_equal(res, exp)
3545

3546
geopandas/tests/test_pandas_methods.py:454: 
3547
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
3548

3549
left = Index([POINT (0 0), POINT (1 1)], dtype='geometry')
3550
right = Index([POINT (0 0), POINT (1 1)], dtype='object'), obj = 'Series.index'
3551

3552
    def _check_types(left, right, obj="Index") -> None:
3553
        if not exact:
3554
            return
3555
    
3556
        assert_class_equal(left, right, exact=exact, obj=obj)
3557
>       assert_attr_equal("inferred_type", left, right, obj=obj)
3558
E       AssertionError: Series.index are different
3559
E       
3560
E       Attribute "inferred_type" are different
3561
E       [left]:  unknown-array
3562
E       [right]: mixed
```

It looks like this pandas change (https://github.com/pandas-dev/pandas/pull/43930) to allow storing extension arrays in the index (that is, not just casting everything to `object`) is responsible.

--- 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/_compat.py`
Content:
```
1 import contextlib
2 from distutils.version import LooseVersion
3 import importlib
4 import os
5 import warnings
6 
7 import numpy as np
8 import pandas as pd
9 import pyproj
10 import shapely
11 import shapely.geos
12 
13 
14 # -----------------------------------------------------------------------------
15 # pandas compat
16 # -----------------------------------------------------------------------------
17 
18 PANDAS_GE_10 = str(pd.__version__) >= LooseVersion("1.0.0")
19 PANDAS_GE_11 = str(pd.__version__) >= LooseVersion("1.1.0")
20 PANDAS_GE_115 = str(pd.__version__) >= LooseVersion("1.1.5")
21 PANDAS_GE_12 = str(pd.__version__) >= LooseVersion("1.2.0")
22 
23 
24 # -----------------------------------------------------------------------------
25 # Shapely / PyGEOS compat
26 # -----------------------------------------------------------------------------
27 
28 
29 SHAPELY_GE_17 = str(shapely.__version__) >= LooseVersion("1.7.0")
30 SHAPELY_GE_18 = str(shapely.__version__) >= LooseVersion("1.8")
31 SHAPELY_GE_20 = str(shapely.__version__) >= LooseVersion("2.0")
32 
33 GEOS_GE_390 = shapely.geos.geos_version >= (3, 9, 0)
34 
35 
36 HAS_PYGEOS = None
37 USE_PYGEOS = None
38 PYGEOS_SHAPELY_COMPAT = None
39 
40 PYGEOS_GE_09 = None
41 PYGEOS_GE_010 = None
42 
43 INSTALL_PYGEOS_ERROR = "To use PyGEOS within GeoPandas, you need to install PyGEOS: \
44 'conda install pygeos' or 'pip install pygeos'"
45 
46 try:
47     import pygeos  # noqa
48 
49     # only automatically use pygeos if version is high enough
50     if str(pygeos.__version__) >= LooseVersion("0.8"):
51         HAS_PYGEOS = True
52         PYGEOS_GE_09 = str(pygeos.__version__) >= LooseVersion("0.9")
53         PYGEOS_GE_010 = str(pygeos.__version__) >= LooseVersion("0.10")
54     else:
55         warnings.warn(
56             "The installed version of PyGEOS is too old ({0} installed, 0.8 required),"
57             " and thus GeoPandas will not use PyGEOS.".format(pygeos.__version__),
58             UserWarning,
59         )
60         HAS_PYGEOS = False
61 except ImportError:
62     HAS_PYGEOS = False
63 
64 
65 def set_use_pygeos(val=None):
66     """
67     Set the global configuration on whether to use PyGEOS or not.
68 
69     The default is use PyGEOS if it is installed. This can be overridden
70     with an environment variable USE_PYGEOS (this is only checked at
71     first import, cannot be changed during interactive session).
72 
73     Alternatively, pass a value here to force a True/False value.
74     """
75     global USE_PYGEOS
76     global PYGEOS_SHAPELY_COMPAT
77 
78     if val is not None:
79         USE_PYGEOS = bool(val)
80     else:
81         if USE_PYGEOS is None:
82 
83             USE_PYGEOS = HAS_PYGEOS
84 
85             env_use_pygeos = os.getenv("USE_PYGEOS", None)
86             if env_use_pygeos is not None:
87                 USE_PYGEOS = bool(int(env_use_pygeos))
88 
89     # validate the pygeos version
90     if USE_PYGEOS:
91         try:
92             import pygeos  # noqa
93 
94             # validate the pygeos version
95             if not str(pygeos.__version__) >= LooseVersion("0.8"):
96                 raise ImportError(
97                     "PyGEOS >= 0.8 is required, version {0} is installed".format(
98                         pygeos.__version__
99                     )
100                 )
101 
102             # Check whether Shapely and PyGEOS use the same GEOS version.
103             # Based on PyGEOS from_shapely implementation.
104 
105             from shapely.geos import geos_version_string as shapely_geos_version
106             from pygeos import geos_capi_version_string
107 
108             # shapely has something like: "3.6.2-CAPI-1.10.2 4d2925d6"
109             # pygeos has something like: "3.6.2-CAPI-1.10.2"
110             if not shapely_geos_version.startswith(geos_capi_version_string):
111                 warnings.warn(
112                     "The Shapely GEOS version ({}) is incompatible with the GEOS "
113                     "version PyGEOS was compiled with ({}). Conversions between both "
114                     "will be slow.".format(
115                         shapely_geos_version, geos_capi_version_string
116                     )
117                 )
118                 PYGEOS_SHAPELY_COMPAT = False
119             else:
120                 PYGEOS_SHAPELY_COMPAT = True
121 
122         except ImportError:
123             raise ImportError(INSTALL_PYGEOS_ERROR)
124 
125 
126 set_use_pygeos()
127 
128 
129 # compat related to deprecation warnings introduced in Shapely 1.8
130 # -> creating a numpy array from a list-like of Multi-part geometries,
131 # although doing the correct thing (not expanding in its parts), still raises
132 # the warning about iteration being deprecated
133 # This adds a context manager to explicitly ignore this warning
134 
135 
136 try:
137     from shapely.errors import ShapelyDeprecationWarning as shapely_warning
138 except ImportError:
139     shapely_warning = None
140 
141 
142 if shapely_warning is not None and not SHAPELY_GE_20:
143 
144     @contextlib.contextmanager
145     def ignore_shapely2_warnings():
146         with warnings.catch_warnings():
147             warnings.filterwarnings(
148                 "ignore", "Iteration|The array interface|__len__", shapely_warning
149             )
150             yield
151 
152 
153 elif (str(np.__version__) >= LooseVersion("1.21")) and not SHAPELY_GE_20:
154 
155     @contextlib.contextmanager
156     def ignore_shapely2_warnings():
157         with warnings.catch_warnings():
158             # warning from numpy for existing Shapely releases (this is fixed
159             # with Shapely 1.8)
160             warnings.filterwarnings(
161                 "ignore", "An exception was ignored while fetching", DeprecationWarning
162             )
163             yield
164 
165 
166 else:
167 
168     @contextlib.contextmanager
169     def ignore_shapely2_warnings():
170         yield
171 
172 
173 def import_optional_dependency(name: str, extra: str = ""):
174     """
175     Import an optional dependency.
176 
177     Adapted from pandas.compat._optional::import_optional_dependency
178 
179     Raises a formatted ImportError if the module is not present.
180 
181     Parameters
182     ----------
183     name : str
184         The module name.
185     extra : str
186         Additional text to include in the ImportError message.
187     Returns
188     -------
189     module
190     """
191     msg = """Missing optional dependency '{name}'. {extra}  "
192         "Use pip or conda to install {name}.""".format(
193         name=name, extra=extra
194     )
195 
196     if not isinstance(name, str):
197         raise ValueError(
198             "Invalid module name: '{name}'; must be a string".format(name=name)
199         )
200 
201     try:
202         module = importlib.import_module(name)
203 
204     except ImportError:
205         raise ImportError(msg) from None
206 
207     return module
208 
209 
210 # -----------------------------------------------------------------------------
211 # RTree compat
212 # -----------------------------------------------------------------------------
213 
214 HAS_RTREE = None
215 RTREE_GE_094 = False
216 try:
217     import rtree  # noqa
218 
219     HAS_RTREE = True
220 except ImportError:
221     HAS_RTREE = False
222 
223 # -----------------------------------------------------------------------------
224 # pyproj compat
225 # -----------------------------------------------------------------------------
226 
227 PYPROJ_LT_3 = LooseVersion(pyproj.__version__) < LooseVersion("3")
228 PYPROJ_GE_31 = LooseVersion(pyproj.__version__) >= LooseVersion("3.1")
229
```
--- 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/_compat.py b/geopandas/_compat.py
--- a/geopandas/_compat.py
+++ b/geopandas/_compat.py
@@ -19,6 +19,7 @@
 PANDAS_GE_11 = str(pd.__version__) >= LooseVersion("1.1.0")
 PANDAS_GE_115 = str(pd.__version__) >= LooseVersion("1.1.5")
 PANDAS_GE_12 = str(pd.__version__) >= LooseVersion("1.2.0")
+PANDAS_GE_14 = str(pd.__version__) >= LooseVersion("1.4.0")
 
 
 # -----------------------------------------------------------------------------

{"golden_diff": "diff --git a/geopandas/_compat.py b/geopandas/_compat.py\n--- a/geopandas/_compat.py\n+++ b/geopandas/_compat.py\n@@ -19,6 +19,7 @@\n PANDAS_GE_11 = str(pd.__version__) >= LooseVersion(\"1.1.0\")\n PANDAS_GE_115 = str(pd.__version__) >= LooseVersion(\"1.1.5\")\n PANDAS_GE_12 = str(pd.__version__) >= LooseVersion(\"1.2.0\")\n+PANDAS_GE_14 = str(pd.__version__) >= LooseVersion(\"1.4.0\")\n \n \n # -----------------------------------------------------------------------------\n", "issue": "TST: test_value_counts breaking against pandas latest\nRecent CI builds on 38-dev.yaml are all failing due to geopandas/tests/test_pandas_methods.py::test_value_counts, which fails with the output:\r\n```\r\n______________________________ test_value_counts _______________________________\r\n3536\r\n[gw0] linux -- Python 3.8.12 /usr/share/miniconda3/envs/test/bin/python\r\n3537\r\n\r\n3538\r\n    def test_value_counts():\r\n3539\r\n        # each object is considered unique\r\n3540\r\n        s = GeoSeries([Point(0, 0), Point(1, 1), Point(0, 0)])\r\n3541\r\n        res = s.value_counts()\r\n3542\r\n        with compat.ignore_shapely2_warnings():\r\n3543\r\n            exp = pd.Series([2, 1], index=[Point(0, 0), Point(1, 1)])\r\n3544\r\n>       assert_series_equal(res, exp)\r\n3545\r\n\r\n3546\r\ngeopandas/tests/test_pandas_methods.py:454: \r\n3547\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n3548\r\n\r\n3549\r\nleft = Index([POINT (0 0), POINT (1 1)], dtype='geometry')\r\n3550\r\nright = Index([POINT (0 0), POINT (1 1)], dtype='object'), obj = 'Series.index'\r\n3551\r\n\r\n3552\r\n    def _check_types(left, right, obj=\"Index\") -> None:\r\n3553\r\n        if not exact:\r\n3554\r\n            return\r\n3555\r\n    \r\n3556\r\n        assert_class_equal(left, right, exact=exact, obj=obj)\r\n3557\r\n>       assert_attr_equal(\"inferred_type\", left, right, obj=obj)\r\n3558\r\nE       AssertionError: Series.index are different\r\n3559\r\nE       \r\n3560\r\nE       Attribute \"inferred_type\" are different\r\n3561\r\nE       [left]:  unknown-array\r\n3562\r\nE       [right]: mixed\r\n```\r\n\r\nIt looks like this pandas change (https://github.com/pandas-dev/pandas/pull/43930) to allow storing extension arrays in the index (that is, not just casting everything to `object`) is responsible.\n", "before_files": [{"content": "import contextlib\nfrom distutils.version import LooseVersion\nimport importlib\nimport os\nimport warnings\n\nimport numpy as np\nimport pandas as pd\nimport pyproj\nimport shapely\nimport shapely.geos\n\n\n# -----------------------------------------------------------------------------\n# pandas compat\n# -----------------------------------------------------------------------------\n\nPANDAS_GE_10 = str(pd.__version__) >= LooseVersion(\"1.0.0\")\nPANDAS_GE_11 = str(pd.__version__) >= LooseVersion(\"1.1.0\")\nPANDAS_GE_115 = str(pd.__version__) >= LooseVersion(\"1.1.5\")\nPANDAS_GE_12 = str(pd.__version__) >= LooseVersion(\"1.2.0\")\n\n\n# -----------------------------------------------------------------------------\n# Shapely / PyGEOS compat\n# -----------------------------------------------------------------------------\n\n\nSHAPELY_GE_17 = str(shapely.__version__) >= LooseVersion(\"1.7.0\")\nSHAPELY_GE_18 = str(shapely.__version__) >= LooseVersion(\"1.8\")\nSHAPELY_GE_20 = str(shapely.__version__) >= LooseVersion(\"2.0\")\n\nGEOS_GE_390 = shapely.geos.geos_version >= (3, 9, 0)\n\n\nHAS_PYGEOS = None\nUSE_PYGEOS = None\nPYGEOS_SHAPELY_COMPAT = None\n\nPYGEOS_GE_09 = None\nPYGEOS_GE_010 = None\n\nINSTALL_PYGEOS_ERROR = \"To use PyGEOS within GeoPandas, you need to install PyGEOS: \\\n'conda install pygeos' or 'pip install pygeos'\"\n\ntry:\n    import pygeos  # noqa\n\n    # only automatically use pygeos if version is high enough\n    if str(pygeos.__version__) >= LooseVersion(\"0.8\"):\n        HAS_PYGEOS = True\n        PYGEOS_GE_09 = str(pygeos.__version__) >= LooseVersion(\"0.9\")\n        PYGEOS_GE_010 = str(pygeos.__version__) >= LooseVersion(\"0.10\")\n    else:\n        warnings.warn(\n            \"The installed version of PyGEOS is too old ({0} installed, 0.8 required),\"\n            \" and thus GeoPandas will not use PyGEOS.\".format(pygeos.__version__),\n            UserWarning,\n        )\n        HAS_PYGEOS = False\nexcept ImportError:\n    HAS_PYGEOS = False\n\n\ndef set_use_pygeos(val=None):\n    \"\"\"\n    Set the global configuration on whether to use PyGEOS or not.\n\n    The default is use PyGEOS if it is installed. This can be overridden\n    with an environment variable USE_PYGEOS (this is only checked at\n    first import, cannot be changed during interactive session).\n\n    Alternatively, pass a value here to force a True/False value.\n    \"\"\"\n    global USE_PYGEOS\n    global PYGEOS_SHAPELY_COMPAT\n\n    if val is not None:\n        USE_PYGEOS = bool(val)\n    else:\n        if USE_PYGEOS is None:\n\n            USE_PYGEOS = HAS_PYGEOS\n\n            env_use_pygeos = os.getenv(\"USE_PYGEOS\", None)\n            if env_use_pygeos is not None:\n                USE_PYGEOS = bool(int(env_use_pygeos))\n\n    # validate the pygeos version\n    if USE_PYGEOS:\n        try:\n            import pygeos  # noqa\n\n            # validate the pygeos version\n            if not str(pygeos.__version__) >= LooseVersion(\"0.8\"):\n                raise ImportError(\n                    \"PyGEOS >= 0.8 is required, version {0} is installed\".format(\n                        pygeos.__version__\n                    )\n                )\n\n            # Check whether Shapely and PyGEOS use the same GEOS version.\n            # Based on PyGEOS from_shapely implementation.\n\n            from shapely.geos import geos_version_string as shapely_geos_version\n            from pygeos import geos_capi_version_string\n\n            # shapely has something like: \"3.6.2-CAPI-1.10.2 4d2925d6\"\n            # pygeos has something like: \"3.6.2-CAPI-1.10.2\"\n            if not shapely_geos_version.startswith(geos_capi_version_string):\n                warnings.warn(\n                    \"The Shapely GEOS version ({}) is incompatible with the GEOS \"\n                    \"version PyGEOS was compiled with ({}). Conversions between both \"\n                    \"will be slow.\".format(\n                        shapely_geos_version, geos_capi_version_string\n                    )\n                )\n                PYGEOS_SHAPELY_COMPAT = False\n            else:\n                PYGEOS_SHAPELY_COMPAT = True\n\n        except ImportError:\n            raise ImportError(INSTALL_PYGEOS_ERROR)\n\n\nset_use_pygeos()\n\n\n# compat related to deprecation warnings introduced in Shapely 1.8\n# -> creating a numpy array from a list-like of Multi-part geometries,\n# although doing the correct thing (not expanding in its parts), still raises\n# the warning about iteration being deprecated\n# This adds a context manager to explicitly ignore this warning\n\n\ntry:\n    from shapely.errors import ShapelyDeprecationWarning as shapely_warning\nexcept ImportError:\n    shapely_warning = None\n\n\nif shapely_warning is not None and not SHAPELY_GE_20:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        with warnings.catch_warnings():\n            warnings.filterwarnings(\n                \"ignore\", \"Iteration|The array interface|__len__\", shapely_warning\n            )\n            yield\n\n\nelif (str(np.__version__) >= LooseVersion(\"1.21\")) and not SHAPELY_GE_20:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        with warnings.catch_warnings():\n            # warning from numpy for existing Shapely releases (this is fixed\n            # with Shapely 1.8)\n            warnings.filterwarnings(\n                \"ignore\", \"An exception was ignored while fetching\", DeprecationWarning\n            )\n            yield\n\n\nelse:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        yield\n\n\ndef import_optional_dependency(name: str, extra: str = \"\"):\n    \"\"\"\n    Import an optional dependency.\n\n    Adapted from pandas.compat._optional::import_optional_dependency\n\n    Raises a formatted ImportError if the module is not present.\n\n    Parameters\n    ----------\n    name : str\n        The module name.\n    extra : str\n        Additional text to include in the ImportError message.\n    Returns\n    -------\n    module\n    \"\"\"\n    msg = \"\"\"Missing optional dependency '{name}'. {extra}  \"\n        \"Use pip or conda to install {name}.\"\"\".format(\n        name=name, extra=extra\n    )\n\n    if not isinstance(name, str):\n        raise ValueError(\n            \"Invalid module name: '{name}'; must be a string\".format(name=name)\n        )\n\n    try:\n        module = importlib.import_module(name)\n\n    except ImportError:\n        raise ImportError(msg) from None\n\n    return module\n\n\n# -----------------------------------------------------------------------------\n# RTree compat\n# -----------------------------------------------------------------------------\n\nHAS_RTREE = None\nRTREE_GE_094 = False\ntry:\n    import rtree  # noqa\n\n    HAS_RTREE = True\nexcept ImportError:\n    HAS_RTREE = False\n\n# -----------------------------------------------------------------------------\n# pyproj compat\n# -----------------------------------------------------------------------------\n\nPYPROJ_LT_3 = LooseVersion(pyproj.__version__) < LooseVersion(\"3\")\nPYPROJ_GE_31 = LooseVersion(pyproj.__version__) >= LooseVersion(\"3.1\")\n", "path": "geopandas/_compat.py"}], "after_files": [{"content": "import contextlib\nfrom distutils.version import LooseVersion\nimport importlib\nimport os\nimport warnings\n\nimport numpy as np\nimport pandas as pd\nimport pyproj\nimport shapely\nimport shapely.geos\n\n\n# -----------------------------------------------------------------------------\n# pandas compat\n# -----------------------------------------------------------------------------\n\nPANDAS_GE_10 = str(pd.__version__) >= LooseVersion(\"1.0.0\")\nPANDAS_GE_11 = str(pd.__version__) >= LooseVersion(\"1.1.0\")\nPANDAS_GE_115 = str(pd.__version__) >= LooseVersion(\"1.1.5\")\nPANDAS_GE_12 = str(pd.__version__) >= LooseVersion(\"1.2.0\")\nPANDAS_GE_14 = str(pd.__version__) >= LooseVersion(\"1.4.0\")\n\n\n# -----------------------------------------------------------------------------\n# Shapely / PyGEOS compat\n# -----------------------------------------------------------------------------\n\n\nSHAPELY_GE_17 = str(shapely.__version__) >= LooseVersion(\"1.7.0\")\nSHAPELY_GE_18 = str(shapely.__version__) >= LooseVersion(\"1.8\")\nSHAPELY_GE_20 = str(shapely.__version__) >= LooseVersion(\"2.0\")\n\nGEOS_GE_390 = shapely.geos.geos_version >= (3, 9, 0)\n\n\nHAS_PYGEOS = None\nUSE_PYGEOS = None\nPYGEOS_SHAPELY_COMPAT = None\n\nPYGEOS_GE_09 = None\nPYGEOS_GE_010 = None\n\nINSTALL_PYGEOS_ERROR = \"To use PyGEOS within GeoPandas, you need to install PyGEOS: \\\n'conda install pygeos' or 'pip install pygeos'\"\n\ntry:\n    import pygeos  # noqa\n\n    # only automatically use pygeos if version is high enough\n    if str(pygeos.__version__) >= LooseVersion(\"0.8\"):\n        HAS_PYGEOS = True\n        PYGEOS_GE_09 = str(pygeos.__version__) >= LooseVersion(\"0.9\")\n        PYGEOS_GE_010 = str(pygeos.__version__) >= LooseVersion(\"0.10\")\n    else:\n        warnings.warn(\n            \"The installed version of PyGEOS is too old ({0} installed, 0.8 required),\"\n            \" and thus GeoPandas will not use PyGEOS.\".format(pygeos.__version__),\n            UserWarning,\n        )\n        HAS_PYGEOS = False\nexcept ImportError:\n    HAS_PYGEOS = False\n\n\ndef set_use_pygeos(val=None):\n    \"\"\"\n    Set the global configuration on whether to use PyGEOS or not.\n\n    The default is use PyGEOS if it is installed. This can be overridden\n    with an environment variable USE_PYGEOS (this is only checked at\n    first import, cannot be changed during interactive session).\n\n    Alternatively, pass a value here to force a True/False value.\n    \"\"\"\n    global USE_PYGEOS\n    global PYGEOS_SHAPELY_COMPAT\n\n    if val is not None:\n        USE_PYGEOS = bool(val)\n    else:\n        if USE_PYGEOS is None:\n\n            USE_PYGEOS = HAS_PYGEOS\n\n            env_use_pygeos = os.getenv(\"USE_PYGEOS\", None)\n            if env_use_pygeos is not None:\n                USE_PYGEOS = bool(int(env_use_pygeos))\n\n    # validate the pygeos version\n    if USE_PYGEOS:\n        try:\n            import pygeos  # noqa\n\n            # validate the pygeos version\n            if not str(pygeos.__version__) >= LooseVersion(\"0.8\"):\n                raise ImportError(\n                    \"PyGEOS >= 0.8 is required, version {0} is installed\".format(\n                        pygeos.__version__\n                    )\n                )\n\n            # Check whether Shapely and PyGEOS use the same GEOS version.\n            # Based on PyGEOS from_shapely implementation.\n\n            from shapely.geos import geos_version_string as shapely_geos_version\n            from pygeos import geos_capi_version_string\n\n            # shapely has something like: \"3.6.2-CAPI-1.10.2 4d2925d6\"\n            # pygeos has something like: \"3.6.2-CAPI-1.10.2\"\n            if not shapely_geos_version.startswith(geos_capi_version_string):\n                warnings.warn(\n                    \"The Shapely GEOS version ({}) is incompatible with the GEOS \"\n                    \"version PyGEOS was compiled with ({}). Conversions between both \"\n                    \"will be slow.\".format(\n                        shapely_geos_version, geos_capi_version_string\n                    )\n                )\n                PYGEOS_SHAPELY_COMPAT = False\n            else:\n                PYGEOS_SHAPELY_COMPAT = True\n\n        except ImportError:\n            raise ImportError(INSTALL_PYGEOS_ERROR)\n\n\nset_use_pygeos()\n\n\n# compat related to deprecation warnings introduced in Shapely 1.8\n# -> creating a numpy array from a list-like of Multi-part geometries,\n# although doing the correct thing (not expanding in its parts), still raises\n# the warning about iteration being deprecated\n# This adds a context manager to explicitly ignore this warning\n\n\ntry:\n    from shapely.errors import ShapelyDeprecationWarning as shapely_warning\nexcept ImportError:\n    shapely_warning = None\n\n\nif shapely_warning is not None and not SHAPELY_GE_20:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        with warnings.catch_warnings():\n            warnings.filterwarnings(\n                \"ignore\", \"Iteration|The array interface|__len__\", shapely_warning\n            )\n            yield\n\n\nelif (str(np.__version__) >= LooseVersion(\"1.21\")) and not SHAPELY_GE_20:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        with warnings.catch_warnings():\n            # warning from numpy for existing Shapely releases (this is fixed\n            # with Shapely 1.8)\n            warnings.filterwarnings(\n                \"ignore\", \"An exception was ignored while fetching\", DeprecationWarning\n            )\n            yield\n\n\nelse:\n\n    @contextlib.contextmanager\n    def ignore_shapely2_warnings():\n        yield\n\n\ndef import_optional_dependency(name: str, extra: str = \"\"):\n    \"\"\"\n    Import an optional dependency.\n\n    Adapted from pandas.compat._optional::import_optional_dependency\n\n    Raises a formatted ImportError if the module is not present.\n\n    Parameters\n    ----------\n    name : str\n        The module name.\n    extra : str\n        Additional text to include in the ImportError message.\n    Returns\n    -------\n    module\n    \"\"\"\n    msg = \"\"\"Missing optional dependency '{name}'. {extra}  \"\n        \"Use pip or conda to install {name}.\"\"\".format(\n        name=name, extra=extra\n    )\n\n    if not isinstance(name, str):\n        raise ValueError(\n            \"Invalid module name: '{name}'; must be a string\".format(name=name)\n        )\n\n    try:\n        module = importlib.import_module(name)\n\n    except ImportError:\n        raise ImportError(msg) from None\n\n    return module\n\n\n# -----------------------------------------------------------------------------\n# RTree compat\n# -----------------------------------------------------------------------------\n\nHAS_RTREE = None\nRTREE_GE_094 = False\ntry:\n    import rtree  # noqa\n\n    HAS_RTREE = True\nexcept ImportError:\n    HAS_RTREE = False\n\n# -----------------------------------------------------------------------------\n# pyproj compat\n# -----------------------------------------------------------------------------\n\nPYPROJ_LT_3 = LooseVersion(pyproj.__version__) < LooseVersion(\"3\")\nPYPROJ_GE_31 = LooseVersion(pyproj.__version__) >= LooseVersion(\"3.1\")\n", "path": "geopandas/_compat.py"}]}