Skip to content

Commit

Permalink
MAINT: reduce warnings in the tests (#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Apr 28, 2024
1 parent b87985c commit 0a21939
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions geopandas/io/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,15 +1113,15 @@ def do_checks(df, index_is_used):
# index as string
df_p = df_points.copy()
df = GeoDataFrame(df_p["value1"], geometry=df_p.geometry)
df.index = pd.TimedeltaIndex(range(len(df)), "days")
df.index = pd.to_timedelta(range(len(df)), unit="days")
# TODO: TimedeltaIndex is an invalid field type
df.index = df.index.astype(str)
do_checks(df, index_is_used=True)

# unnamed DatetimeIndex
df_p = df_points.copy()
df = GeoDataFrame(df_p["value1"], geometry=df_p.geometry)
df.index = pd.TimedeltaIndex(range(len(df)), "days") + pd.DatetimeIndex(
df.index = pd.to_timedelta(range(len(df)), unit="days") + pd.to_datetime(
["1999-12-27"] * len(df)
)
if driver == "ESRI Shapefile":
Expand Down
24 changes: 15 additions & 9 deletions geopandas/io/tests/test_file_geom_types_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@ def geodataframe(request):
return request.param


@pytest.fixture(params=["GeoJSON", "ESRI Shapefile", "GPKG", "SQLite"])
@pytest.fixture(
params=[
("GeoJSON", ".geojson"),
("ESRI Shapefile", ".shp"),
("GPKG", ".gpkg"),
("SQLite", ".sqlite"),
]
)
def ogr_driver(request):
return request.param

Expand All @@ -260,9 +267,10 @@ def engine(request):


def test_to_file_roundtrip(tmpdir, geodataframe, ogr_driver, engine):
output_file = os.path.join(str(tmpdir), "output_file")
driver, ext = ogr_driver
output_file = os.path.join(str(tmpdir), "output_file" + ext)
write_kwargs = {}
if ogr_driver == "SQLite":
if driver == "SQLite":
write_kwargs["spatialite"] = True

# This if statement can be removed once minimal fiona version >= 1.8.20
Expand All @@ -285,22 +293,20 @@ def test_to_file_roundtrip(tmpdir, geodataframe, ogr_driver, engine):
):
write_kwargs["geometry_type"] = "Point Z"

expected_error = _expected_error_on(geodataframe, ogr_driver)
expected_error = _expected_error_on(geodataframe, driver)
if expected_error:
with pytest.raises(
RuntimeError, match="Failed to write record|Could not add feature to layer"
):
geodataframe.to_file(
output_file, driver=ogr_driver, engine=engine, **write_kwargs
output_file, driver=driver, engine=engine, **write_kwargs
)
else:
geodataframe.to_file(
output_file, driver=ogr_driver, engine=engine, **write_kwargs
)
geodataframe.to_file(output_file, driver=driver, engine=engine, **write_kwargs)

reloaded = geopandas.read_file(output_file, engine=engine)

if ogr_driver == "GeoJSON" and engine == "pyogrio":
if driver == "GeoJSON" and engine == "pyogrio":
# For GeoJSON files, the int64 column comes back as int32
reloaded["a"] = reloaded["a"].astype("int64")

Expand Down
12 changes: 6 additions & 6 deletions geopandas/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ def test_as_array():
("geom_almost_equals", (3,)),
],
)
@pytest.mark.filterwarnings(
r"ignore:The \'almost_equals\(\)\' method is deprecated"
) # filter required for attr=geom_almost_equals only
# filters required for attr=geom_almost_equals only
@pytest.mark.filterwarnings(r"ignore:The \'geom_almost_equals\(\)\' method is deprecat")
@pytest.mark.filterwarnings(r"ignore:The \'almost_equals\(\)\' method is deprecated")
def test_predicates_vector_scalar(attr, args):
na_value = False

Expand Down Expand Up @@ -323,9 +323,9 @@ def test_predicates_vector_scalar(attr, args):
("geom_almost_equals", (3,)),
],
)
@pytest.mark.filterwarnings(
r"ignore:The \'almost_equals\(\)\' method is deprecated"
) # filter required for attr=geom_almost_equals only
# filters required for attr=geom_almost_equals only
@pytest.mark.filterwarnings(r"ignore:The \'geom_almost_equals\(\)\' method is deprecat")
@pytest.mark.filterwarnings(r"ignore:The \'almost_equals\(\)\' method is deprecated")
def test_predicates_vector_vector(attr, args):
na_value = False
empty_value = True if attr == "disjoint" else False
Expand Down
6 changes: 6 additions & 0 deletions geopandas/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def test_to_crs_dimension_z():
assert result.has_z.all()


# pyproj + numpy 1.25 trigger warning for single-element array -> recommdation is to
# ignore the warning for now (https://github.com/pyproj4/pyproj/issues/1307)
@pytest.mark.filterwarnings("ignore:Conversion of an array with:DeprecationWarning")
def test_to_crs_dimension_mixed():
s = GeoSeries([Point(1, 2), LineString([(1, 2, 3), (4, 5, 6)])], crs=2056)
result = s.to_crs(epsg=4326)
Expand Down Expand Up @@ -151,6 +154,9 @@ def test_transform2(epsg4326, epsg26918):
assert_geodataframe_equal(df, utm, check_less_precise=True, check_crs=False)


# pyproj + numpy 1.25 trigger warning for single-element array -> recommdation is to
# ignore the warning for now (https://github.com/pyproj4/pyproj/issues/1307)
@pytest.mark.filterwarnings("ignore:Conversion of an array with:DeprecationWarning")
def test_crs_axis_order__always_xy():
df = GeoDataFrame(geometry=[Point(-1683723, 6689139)], crs="epsg:26918")
lonlat = df.to_crs("epsg:4326")
Expand Down
2 changes: 1 addition & 1 deletion geopandas/tests/test_geom_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ def test_extract_unique_points_not_implemented(self):
def test_minimum_bounding_circle(self):
mbc = self.g1.minimum_bounding_circle()
centers = GeoSeries([Point(0.5, 0.5)] * 2)
assert np.all(mbc.centroid.geom_almost_equals(centers, 0.001))
assert np.all(mbc.centroid.geom_equals_exact(centers, 0.001))
assert_series_equal(
mbc.area,
Series([1.560723, 1.560723]),
Expand Down
3 changes: 3 additions & 0 deletions geopandas/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,9 @@ def test_manual(self):
assert ax3.get_aspect() == 0.5


@pytest.mark.filterwarnings(
"ignore:Numba not installed. Using slow pure python version.:UserWarning"
)
class TestMapclassifyPlotting:
@classmethod
def setup_class(cls):
Expand Down

0 comments on commit 0a21939

Please sign in to comment.