Skip to content

Commit

Permalink
Fix is_jsonable if integer key in dict (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Feb 13, 2025
1 parent 0c1e566 commit 166f174
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/huggingface_hub/utils/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def is_jsonable(obj: Any) -> bool:
if isinstance(obj, (list, tuple)):
return all(is_jsonable(item) for item in obj)
if isinstance(obj, dict):
return all(isinstance(key, str) and is_jsonable(value) for key, value in obj.items())
return all(isinstance(key, _JSON_SERIALIZABLE_TYPES) and is_jsonable(value) for key, value in obj.items())
if hasattr(obj, "__json__"):
return True
return False
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CustomType:
[(1, 2.0, "string"), True],
{},
{"name": "Alice", "age": 30},
{0: "LABEL_0", 1.0: "LABEL_1"},
],
)
def test_is_jsonable_success(data):
Expand Down

0 comments on commit 166f174

Please sign in to comment.