Skip to content

Commit 6bd6e8b

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Handle missing card data values
PiperOrigin-RevId: 638959328
1 parent 465d709 commit 6bd6e8b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tensorflow_datasets/core/dataset_builders/huggingface_dataset_builder.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,14 @@ def _get_license(self) -> str | None:
417417
repo_id, token = self._hf_repo_id, self._hf_hub_token
418418
dataset_info = huggingface_hub.dataset_info(repo_id, token=token)
419419
# Second heuristic: check the card data.
420-
if 'license' in dataset_info.card_data:
421-
return dataset_info.card_data['license']
420+
if dataset_info.card_data:
421+
if card_data_license := dataset_info.card_data.get('license'):
422+
return card_data_license
422423
# Third heuristic: check the tags.
423-
for tag in dataset_info.tags:
424-
if tag.startswith('license:'):
425-
return tag[len('license:') :]
424+
if dataset_info.tags:
425+
for tag in dataset_info.tags:
426+
if tag.startswith('license:'):
427+
return tag.removeprefix('license:')
426428
return None
427429

428430

0 commit comments

Comments
 (0)