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

Fix bounds error in shapereader for null records #2188

Merged
merged 2 commits into from
Jun 13, 2023

Conversation

lgolston
Copy link
Contributor

@lgolston lgolston commented Jun 9, 2023

Rationale

As identified in issue #2087, FionaReader is currently throwing an error when iterating through the records,of the 10m Natural Earth rivers shapefile for North America, due to some entries that have attributes but no geometry. Since geometry is None in those cases, calling geometry.bounds fails. I checked and this is new to version 5.0.0 of the shapefile - the previous 4.1.0 version works without error.

Implications

The bug should be fixed.

@dopplershift
Copy link
Contributor

Is the bounds property not used by our codebase at all? It would seem that while your patch fixes the initial problem, it would only delay failure until that property from the base Record class is accessed:

@property
def bounds(self):
"""
The bounds of this Record's :meth:`~Record.geometry`.
"""
if self._bounds is None:
self._bounds = self.geometry.bounds
return self._bounds

@lgolston
Copy link
Contributor Author

lgolston commented Jun 9, 2023

That is an interesting question @dopplershift. I am not sure if it is used anywhere, but will look at editing the property definition you have highlighted since looking now it produces an error with both BasicReader and FionaReader on this dataset.

@lgolston
Copy link
Contributor Author

The bounds property of class Record is now modified with the same check in case it is called.

I also looked at test_shapereader, and found it was only testing FionaReader (if fiona installed). The PR now modifies it to test both Readers, improving branch coverage for shapereader.

@lgolston lgolston changed the title Fix bounds error FionaReader Fix bounds error in shapereader for null records Jun 12, 2023
@dopplershift dopplershift added this to the 0.21.2 milestone Jun 13, 2023
@dopplershift dopplershift merged commit 2abf4fd into SciTools:main Jun 13, 2023
@dopplershift
Copy link
Contributor

Thanks for the fix @lgolston !

@lgolston lgolston deleted the fiona-record-bug branch June 14, 2023 02:23
@greglucas greglucas modified the milestones: 0.21.2, 0.22 Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants