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

EuroCrops: handle Nones in get_label #2499

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions tests/datasets/test_eurocrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def test_invalid_query(self, dataset: EuroCrops) -> None:
):
dataset[query]

def test_get_label_with_none_hcat_code(self, dataset: EuroCrops) -> None:
mock_feature = {'properties': {dataset.label_name: None}}
label = dataset.get_label(mock_feature)
assert label == 0, "Expected label to be 0 when 'EC_hcat_c' is None."

def test_integrity_error(self, dataset: EuroCrops) -> None:
dataset.zenodo_files = (('AA.zip', 'invalid'),)
assert not dataset._check_integrity()
3 changes: 3 additions & 0 deletions torchgeo/datasets/eurocrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def get_label(self, feature: 'fiona.model.Feature') -> int:
# We go up the class hierarchy until there is a match.
# (Parent code is computed by replacing rightmost non-0 character with 0.)
hcat_code = feature['properties'][self.label_name]
if hcat_code is None:
return 0

while True:
if hcat_code in self.class_map:
return self.class_map[hcat_code]
Expand Down
Loading