This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
Prevent empty fields from rendering as "None" #251
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this pull request do?
This change fixes a bug that made empty objects render as "None" by:
__len__()
for model card fields that ignoresNone
values recursively when counting items, meaning empty fields and nested empty fields will be falsyThis also fixes a bug where nested empty were being serialized when writing a model card to a proto since they were truthy.
Example usage of
len()
andbool()
:If you're recreating a model card from a proto, use
if model_card is None
instead ofif not model_card
to test whether the operation was successful if you want to fail onNone
but not onModelCard()
.Fixes #213
How did you test this change?
Screenshot from the offical MLMD Model Card Toolkit Demo:
Screenshot from running the demo notebook with this fix implemented:
How did you document this change?
Docstrings
Before submitting
Before submitting a pull request, please be sure to do the following: