TST: fix test_value_counts test for pandas 1.4 (#2289)

This commit is contained in:
Matt Richards
2022-01-09 14:50:52 +01:00
committed by GitHub
parent 831108dcb3
commit 3d53170d4c
2 changed files with 16 additions and 4 deletions
+1
View File
@@ -19,6 +19,7 @@ PANDAS_GE_10 = str(pd.__version__) >= LooseVersion("1.0.0")
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")
# -----------------------------------------------------------------------------
+15 -4
View File
@@ -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)