Backport upstream PR’s #2219, #2289, #2298, and #2320 in order to resolve test failures with pandas 1.4. It seems that PR#2320 may also be needed for pandas 1.3.5, which should have been a compatible release.
199 lines
8 KiB
Diff
199 lines
8 KiB
Diff
From f5998c419aef31d237a2bd316199cc6351221c4c Mon Sep 17 00:00:00 2001
|
|
From: Matt Richards <mrichards7@outlook.com.au>
|
|
Date: Wed, 5 Jan 2022 12:21:21 +1000
|
|
Subject: [PATCH 1/5] TST: fix test_value_counts pandas master
|
|
|
|
---
|
|
geopandas/_compat.py | 1 +
|
|
geopandas/tests/test_pandas_methods.py | 19 +++++++++++++++----
|
|
2 files changed, 16 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/geopandas/_compat.py b/geopandas/_compat.py
|
|
index e5ac045df..9fe9e124a 100644
|
|
--- 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_20 = str(pd.__version__) > LooseVersion("1.4.0.dev")
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
|
|
index 709ad3da0..f9ce67e86 100644
|
|
--- 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 pd20_compat_index(index):
|
|
+ if compat.PANDAS_GE_20:
|
|
+ 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=pd20_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_20:
|
|
+ # 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 = pd20_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=pd20_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=pd20_compat_index([Point(0, 0), None]))
|
|
res4_keepna = s4.value_counts(dropna=False)
|
|
assert_series_equal(res4_keepna, exp4_keepna)
|
|
|
|
|
|
From ecff4fd976fa619ae9f9792904ec1ecc291f092d Mon Sep 17 00:00:00 2001
|
|
From: Matt Richards <45483497+m-richards@users.noreply.github.com>
|
|
Date: Sun, 9 Jan 2022 21:43:42 +1000
|
|
Subject: [PATCH 2/5] Update geopandas/_compat.py
|
|
|
|
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
|
|
---
|
|
geopandas/_compat.py | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/geopandas/_compat.py b/geopandas/_compat.py
|
|
index 9fe9e124a..000db2a60 100644
|
|
--- a/geopandas/_compat.py
|
|
+++ b/geopandas/_compat.py
|
|
@@ -19,7 +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_20 = str(pd.__version__) > LooseVersion("1.4.0.dev")
|
|
+PANDAS_GE_14 = str(pd.__version__) >= LooseVersion("1.4.0")
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
From 9f22ee43d6960d7c8b6cfdc1907e8e424dc99ba7 Mon Sep 17 00:00:00 2001
|
|
From: Matt Richards <45483497+m-richards@users.noreply.github.com>
|
|
Date: Sun, 9 Jan 2022 21:44:25 +1000
|
|
Subject: [PATCH 3/5] Update geopandas/tests/test_pandas_methods.py
|
|
|
|
---
|
|
geopandas/tests/test_pandas_methods.py | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
|
|
index f9ce67e86..82a03869e 100644
|
|
--- a/geopandas/tests/test_pandas_methods.py
|
|
+++ b/geopandas/tests/test_pandas_methods.py
|
|
@@ -446,7 +446,7 @@ def test_unique():
|
|
|
|
|
|
def pd20_compat_index(index):
|
|
- if compat.PANDAS_GE_20:
|
|
+ if compat.PANDAS_GE_14:
|
|
return from_shapely(index)
|
|
else:
|
|
return index
|
|
|
|
From 2281d167eba59df24a80607d28d6e54c9a20fedd Mon Sep 17 00:00:00 2001
|
|
From: Matt Richards <45483497+m-richards@users.noreply.github.com>
|
|
Date: Sun, 9 Jan 2022 21:45:04 +1000
|
|
Subject: [PATCH 4/5] Update test_pandas_methods.py
|
|
|
|
---
|
|
geopandas/tests/test_pandas_methods.py | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
|
|
index 82a03869e..a78e9f0df 100644
|
|
--- a/geopandas/tests/test_pandas_methods.py
|
|
+++ b/geopandas/tests/test_pandas_methods.py
|
|
@@ -463,7 +463,7 @@ def test_value_counts():
|
|
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_20:
|
|
+ if compat.PANDAS_GE_14:
|
|
# TODO should/ can we fix CRS being lost
|
|
assert s2.value_counts().index.array.crs is None
|
|
|
|
|
|
From 40eb9185c7e18bebf5b6e3cb8da6de7d5520e81f Mon Sep 17 00:00:00 2001
|
|
From: Matt Richards <mrichards7@outlook.com.au>
|
|
Date: Sun, 9 Jan 2022 21:46:59 +1000
|
|
Subject: [PATCH 5/5] CLN: finish renames
|
|
|
|
---
|
|
geopandas/tests/test_pandas_methods.py | 10 +++++-----
|
|
1 file changed, 5 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
|
|
index a78e9f0df..ed080af46 100644
|
|
--- a/geopandas/tests/test_pandas_methods.py
|
|
+++ b/geopandas/tests/test_pandas_methods.py
|
|
@@ -445,7 +445,7 @@ def test_unique():
|
|
assert_array_equal(s.unique(), exp)
|
|
|
|
|
|
-def pd20_compat_index(index):
|
|
+def pd14_compat_index(index):
|
|
if compat.PANDAS_GE_14:
|
|
return from_shapely(index)
|
|
else:
|
|
@@ -457,7 +457,7 @@ def test_value_counts():
|
|
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=pd20_compat_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")
|
|
@@ -470,7 +470,7 @@ def test_value_counts():
|
|
# check mixed geometry
|
|
s3 = GeoSeries([Point(0, 0), LineString([[1, 1], [2, 2]]), Point(0, 0)])
|
|
res3 = s3.value_counts()
|
|
- index = pd20_compat_index([Point(0, 0), LineString([[1, 1], [2, 2]])])
|
|
+ index = pd14_compat_index([Point(0, 0), LineString([[1, 1], [2, 2]])])
|
|
with compat.ignore_shapely2_warnings():
|
|
exp3 = pd.Series([2, 1], index=index)
|
|
assert_series_equal(res3, exp3)
|
|
@@ -479,10 +479,10 @@ def test_value_counts():
|
|
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=pd20_compat_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=pd20_compat_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)
|
|
|