Skip to content

Commit

Permalink
Merge branch 'main' into prepare-for-0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
hanouticelina authored Oct 22, 2024
2 parents c134f28 + 40a64c8 commit ec5123a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def __post_init__(self): # hack to make BlobLfsInfo backward compatible

@dataclass
class BlobSecurityInfo(dict):
safe: bool
safe: bool # duplicate information with "status" field, keeping it for backward compatibility
status: str
av_scan: Optional[Dict]
pickle_import_scan: Optional[Dict]

Expand Down Expand Up @@ -642,10 +643,14 @@ def __init__(self, **kwargs):
oid=last_commit["id"], title=last_commit["title"], date=parse_datetime(last_commit["date"])
)
self.last_commit = last_commit
security = kwargs.pop("security", None)
security = kwargs.pop("securityFileStatus", None)
if security is not None:
safe = security["status"] == "safe"
security = BlobSecurityInfo(
safe=security["safe"], av_scan=security["avScan"], pickle_import_scan=security["pickleImportScan"]
safe=safe,
status=security["status"],
av_scan=security["avScan"],
pickle_import_scan=security["pickleImportScan"],
)
self.security = security

Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def to_dict(self):

data_dict = copy.deepcopy(self.__dict__)
self._to_dict(data_dict)
return _remove_none(data_dict)
return {key: value for key, value in data_dict.items() if value is not None}

def _to_dict(self, data_dict):
"""Use this method in child classes to alter the dict representation of the data. Alter the dict in-place.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ def test_model_card_unique_tags(self):
data = ModelCardData(tags=["tag2", "tag1", "tag2", "tag3"])
assert data.tags == ["tag2", "tag1", "tag3"]

def test_remove_top_level_none_values(self):
as_obj = ModelCardData(tags=["tag1", None], foo={"bar": 3, "baz": None}, pipeline_tag=None)
as_dict = as_obj.to_dict()

assert as_obj.tags == ["tag1", None]
assert as_dict["tags"] == ["tag1", None] # none value inside list should be kept

assert as_obj.foo == {"bar": 3, "baz": None}
assert as_dict["foo"] == {"bar": 3, "baz": None} # none value inside dict should be kept

assert as_obj.pipeline_tag is None
assert "pipeline_tag" not in as_dict # top level none value should be removed


class DatasetCardDataTest(unittest.TestCase):
def test_train_eval_index_keys_updated(self):
Expand Down

0 comments on commit ec5123a

Please sign in to comment.