Skip to content
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

BUG: Enable mask & bbox filter when geometry column not read #431

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

- Silence warning from `write_dataframe` with `GeoSeries.notna()` (#435).
- BUG: Enable mask & bbox filter when geometry column not read (#431).

## 0.9.0 (2024-06-17)

Expand Down
2 changes: 1 addition & 1 deletion pyogrio/_io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ def ogr_read(
idx = np.intersect1d(fields[:,2], columns, return_indices=True)[1]
fields = fields[idx, :]

if not read_geometry:
if not read_geometry and bbox is None and mask is None:
ignored_fields.append("OGR_GEOMETRY")

# Instruct GDAL to ignore reading fields not
Expand Down
25 changes: 25 additions & 0 deletions pyogrio/tests/test_raw_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ def test_read_no_geometry(naturalearth_lowres):
assert geometry is None


@pytest.mark.skipif(
not HAS_SHAPELY, reason="Shapely is required for mask functionality"
)
def test_read_no_geometry__mask(naturalearth_lowres):
geometry, fields = read(
naturalearth_lowres,
read_geometry=False,
mask=shapely.Point(-105, 55),
)[2:]

assert np.array_equal(fields[3], ["CAN"])
assert geometry is None


def test_read_no_geometry__bbox(naturalearth_lowres):
geometry, fields = read(
naturalearth_lowres,
read_geometry=False,
bbox=(-109.0, 55.0, -109.0, 55.0),
)[2:]

assert np.array_equal(fields[3], ["CAN"])
assert geometry is None


def test_read_no_geometry_no_columns_no_fids(naturalearth_lowres):
with pytest.raises(
ValueError,
Expand Down
Loading