mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-11 12:10:59 +08:00
TST: fix pytest 8 deprecation warnings (#2507)
* TST: fix pytest 8 deprecation warnings * TST: catch pandas append deprecationwarnings * missing one pytest in 8 * filter futurewarning * get rid of concat warning * CLN: simplify warning filtering
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
@@ -289,7 +291,7 @@ def test_dissolve_dropna():
|
||||
)
|
||||
def test_dissolve_dropna_warn(nybb_polydf):
|
||||
# No warning with default params
|
||||
with pytest.warns(None) as record:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
nybb_polydf.dissolve()
|
||||
|
||||
for r in record:
|
||||
@@ -308,7 +310,7 @@ def test_dissolve_multi_agg(nybb_polydf, merged_shapes):
|
||||
merged_shapes[("BoroCode", "max")] = [5, 2]
|
||||
merged_shapes[("BoroName", "count")] = [3, 2]
|
||||
|
||||
with pytest.warns(None) as record:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
test = nybb_polydf.dissolve(
|
||||
by="manhattan_bronx",
|
||||
aggfunc={
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import string
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from numpy.testing import assert_array_equal
|
||||
@@ -867,7 +868,7 @@ class TestGeomMethods:
|
||||
with pytest.warns(UserWarning, match="Geometry is in a geographic CRS"):
|
||||
self.g4.buffer(1)
|
||||
|
||||
with pytest.warns(None) as record:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
# do not warn for 0
|
||||
self.g4.buffer(0)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import random
|
||||
import shutil
|
||||
import tempfile
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from numpy.testing import assert_array_equal
|
||||
@@ -122,13 +123,13 @@ class TestSeries:
|
||||
# Test that warning is not issued when operating on aligned series
|
||||
a1, a2 = self.a1.align(self.a2)
|
||||
|
||||
with pytest.warns(None) as warnings:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
a1.contains(a2) # _series_op, explicitly aligned
|
||||
self.g1.intersects(self.g2) # _series_op, implicitly aligned
|
||||
a2.union(a1) # _geo_op, explicitly aligned
|
||||
self.g2.intersection(self.g1) # _geo_op, implicitly aligned
|
||||
|
||||
user_warnings = [w for w in warnings if w.category is UserWarning]
|
||||
user_warnings = [w for w in record if w.category is UserWarning]
|
||||
assert not user_warnings, user_warnings[0].message
|
||||
|
||||
def test_geom_equals(self):
|
||||
@@ -510,7 +511,7 @@ class TestConstructor:
|
||||
np.array([], dtype="float64"),
|
||||
np.array([], dtype="str"),
|
||||
]:
|
||||
with pytest.warns(None) as record:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
s = GeoSeries(arr)
|
||||
assert not record
|
||||
assert isinstance(s, GeoSeries)
|
||||
|
||||
@@ -302,8 +302,10 @@ def test_to_csv(df):
|
||||
assert df.to_csv(index=False) == exp
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
"ignore:Dropping of nuisance columns in DataFrame reductions"
|
||||
)
|
||||
def test_numerical_operations(s, df):
|
||||
|
||||
# df methods ignore the geometry column
|
||||
exp = pd.Series([3, 4], index=["value1", "value2"])
|
||||
assert_series_equal(df.sum(), exp)
|
||||
|
||||
@@ -620,7 +620,7 @@ class TestPolygonPlotting:
|
||||
|
||||
t3 = Polygon([(2, 0), (3, 0), (3, 1)])
|
||||
df_nan = GeoDataFrame({"geometry": t3, "values": [np.nan]})
|
||||
self.df3 = self.df.append(df_nan)
|
||||
self.df3 = pd.concat([self.df, df_nan])
|
||||
|
||||
def test_single_color(self):
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ class TestSeriesSindex:
|
||||
s = GeoSeries([t1, t2, sq])
|
||||
assert s.sindex.size == 3
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:The series.append method is deprecated")
|
||||
def test_polygons_append(self):
|
||||
t1 = Polygon([(0, 0), (1, 0), (1, 1)])
|
||||
t2 = Polygon([(0, 0), (1, 1), (0, 1)])
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
||||
from shapely.geometry import Point, Polygon
|
||||
@@ -125,7 +127,7 @@ def test_ignore_crs_mismatch():
|
||||
|
||||
# assert that with `check_crs=False` the assert passes, and also does not
|
||||
# generate any warning from comparing both geometries with different crs
|
||||
with pytest.warns(None) as record:
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
assert_geodataframe_equal(df1, df2, check_crs=False)
|
||||
|
||||
assert len(record) == 0
|
||||
|
||||
@@ -531,9 +531,9 @@ class TestSpatialJoinNYBB:
|
||||
def test_sjoin_empty_geometries(self):
|
||||
# https://github.com/geopandas/geopandas/issues/944
|
||||
empty = GeoDataFrame(geometry=[GeometryCollection()] * 3)
|
||||
df = sjoin(self.pointdf.append(empty), self.polydf, how="left")
|
||||
df = sjoin(pd.concat([self.pointdf, empty]), self.polydf, how="left")
|
||||
assert df.shape == (24, 8)
|
||||
df2 = sjoin(self.pointdf, self.polydf.append(empty), how="left")
|
||||
df2 = sjoin(self.pointdf, pd.concat([self.polydf, empty]), how="left")
|
||||
assert df2.shape == (21, 8)
|
||||
|
||||
@pytest.mark.parametrize("predicate", ["intersects", "within", "contains"])
|
||||
|
||||
Reference in New Issue
Block a user