-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: raise Python warnings instead of printing to stderr for GDAL Warning messages #242
Changes from all commits
7580b29
4536542
b7d88cb
6b7cb0e
a2de6e4
583e640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import contextlib | ||
import json | ||
import os | ||
import sys | ||
|
@@ -270,6 +271,7 @@ def test_write(tmpdir, naturalearth_lowres): | |
|
||
def test_write_gpkg(tmpdir, naturalearth_lowres): | ||
meta, _, geometry, field_data = read(naturalearth_lowres) | ||
meta.update({"geometry_type": "MultiPolygon"}) | ||
|
||
filename = os.path.join(str(tmpdir), "test.gpkg") | ||
write(filename, geometry, field_data, driver="GPKG", **meta) | ||
|
@@ -456,9 +458,11 @@ def assert_equal_result(result1, result2): | |
assert all([np.array_equal(f1, f2) for f1, f2 in zip(field_data1, field_data2)]) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:File /vsimem:RuntimeWarning") # TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When reading from bytes / file-like objects, we create a vsimem temporary in-memory file, but because we don't know the file type at that moment, we get a warning like "File /vsimem/5332805636f74498b74520a2c132082b has GPKG application_id, but non conformant file extension" |
||
@pytest.mark.parametrize("driver,ext", [("GeoJSON", "geojson"), ("GPKG", "gpkg")]) | ||
def test_read_from_bytes(tmpdir, naturalearth_lowres, driver, ext): | ||
meta, index, geometry, field_data = read(naturalearth_lowres) | ||
meta.update({"geometry_type": "Unknown"}) | ||
filename = os.path.join(str(tmpdir), f"test.{ext}") | ||
write(filename, geometry, field_data, driver=driver, **meta) | ||
|
||
|
@@ -480,9 +484,11 @@ def test_read_from_bytes_zipped(tmpdir, naturalearth_lowres_vsi): | |
assert_equal_result((meta, index, geometry, field_data), result2) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:File /vsimem:RuntimeWarning") # TODO | ||
@pytest.mark.parametrize("driver,ext", [("GeoJSON", "geojson"), ("GPKG", "gpkg")]) | ||
def test_read_from_file_like(tmpdir, naturalearth_lowres, driver, ext): | ||
meta, index, geometry, field_data = read(naturalearth_lowres) | ||
meta.update({"geometry_type": "Unknown"}) | ||
filename = os.path.join(str(tmpdir), f"test.{ext}") | ||
write(filename, geometry, field_data, driver=driver, **meta) | ||
|
||
|
@@ -647,7 +653,12 @@ def test_write_float_nan_null(tmp_path, dtype): | |
|
||
# set to False | ||
# by default, GDAL will skip the property for GeoJSON if the value is NaN | ||
write(fname, geometry, field_data, fields, **meta, nan_as_null=False) | ||
if dtype == "float32": | ||
ctx = pytest.warns(RuntimeWarning, match="NaN of Infinity value found. Skipped") | ||
else: | ||
ctx = contextlib.nullcontext() | ||
Comment on lines
+656
to
+659
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is bizarre, but for some reason GDAL only raise the warning if the dtype is float32, while the value is actually skipped for both float32 and float64 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like an issue to raise upstream? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so the issue seems to be that it only warns once, not depending on float32 vs float64. I would expect it to warn once per file, and not once per session, though |
||
with ctx: | ||
write(fname, geometry, field_data, fields, **meta, nan_as_null=False) | ||
with open(str(fname), "r") as f: | ||
content = f.read() | ||
assert '"properties": { }' in content | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that reading the Shapefile will indicate the geometry type is "Polygon" (because shapefiles don't care about the distinction), but then using that
meta
to write to geopackage will raise a warning because geopackage is stricter