Repository: geopandas/geopandas

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.


Discussion:

Resolving patch:
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")
 
 
 # -----------------------------------------------------------------------------


Test patch:
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
--- a/geopandas/tests/test_pandas_methods.py
+++ b/geopandas/tests/test_pandas_methods.py
@@ -445,33 +445,44 @@ def test_unique():
     assert_array_equal(s.unique(), exp)
 
 
+def pd14_compat_index(index):
+    if compat.PANDAS_GE_14:
+        return from_shapely(index)
+    else:
+        return index
+
+
 def test_value_counts():
     # each object is considered unique
     s = GeoSeries([Point(0, 0), Point(1, 1), Point(0, 0)])
     res = s.value_counts()
     with compat.ignore_shapely2_warnings():
-        exp = pd.Series([2, 1], index=[Point(0, 0), Point(1, 1)])
+        exp = pd.Series([2, 1], index=pd14_compat_index([Point(0, 0), Point(1, 1)]))
     assert_series_equal(res, exp)
     # Check crs doesn't make a difference - note it is not kept in output index anyway
     s2 = GeoSeries([Point(0, 0), Point(1, 1), Point(0, 0)], crs="EPSG:4326")
     res2 = s2.value_counts()
     assert_series_equal(res2, exp)
+    if compat.PANDAS_GE_14:
+        # TODO should/ can we fix CRS being lost
+        assert s2.value_counts().index.array.crs is None
 
     # check mixed geometry
     s3 = GeoSeries([Point(0, 0), LineString([[1, 1], [2, 2]]), Point(0, 0)])
     res3 = s3.value_counts()
+    index = pd14_compat_index([Point(0, 0), LineString([[1, 1], [2, 2]])])
     with compat.ignore_shapely2_warnings():
-        exp3 = pd.Series([2, 1], index=[Point(0, 0), LineString([[1, 1], [2, 2]])])
+        exp3 = pd.Series([2, 1], index=index)
     assert_series_equal(res3, exp3)
 
     # check None is handled
     s4 = GeoSeries([Point(0, 0), None, Point(0, 0)])
     res4 = s4.value_counts(dropna=True)
     with compat.ignore_shapely2_warnings():
-        exp4_dropna = pd.Series([2], index=[Point(0, 0)])
+        exp4_dropna = pd.Series([2], index=pd14_compat_index([Point(0, 0)]))
     assert_series_equal(res4, exp4_dropna)
     with compat.ignore_shapely2_warnings():
-        exp4_keepna = pd.Series([2, 1], index=[Point(0, 0), None])
+        exp4_keepna = pd.Series([2, 1], index=pd14_compat_index([Point(0, 0), None]))
     res4_keepna = s4.value_counts(dropna=False)
     assert_series_equal(res4_keepna, exp4_keepna)