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

Fixed the issue #2535 Added user followers and following in class User and added test cases for it #2536

Merged
merged 5 commits into from
Sep 17, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,10 @@ class User:
Number of upvotes received by the user.
num_likes (`int`, *optional*):
Number of likes given by the user.
num_following (`int`, *optional*):
Number of users this user is following.
num_followers (`int`, *optional*):
Number of users following this user.
orgs (list of [`Organization`]):
List of organizations the user is part of.
"""
Expand All @@ -1423,6 +1427,8 @@ class User:
num_papers: Optional[int] = None
num_upvotes: Optional[int] = None
num_likes: Optional[int] = None
num_following: Optional[int] = None
num_followers: Optional[int] = None
orgs: List[Organization] = field(default_factory=list)

def __init__(self, **kwargs) -> None:
Expand All @@ -1439,6 +1445,8 @@ def __init__(self, **kwargs) -> None:
self.num_papers = kwargs.pop("numPapers", None)
self.num_upvotes = kwargs.pop("numUpvotes", None)
self.num_likes = kwargs.pop("numLikes", None)
self.num_following = kwargs.pop("numFollowing", None)
self.num_followers = kwargs.pop("numFollowers", None)
self.user_type = kwargs.pop("type", None)
self.orgs = [Organization(**org) for org in kwargs.pop("orgs", [])]

Expand Down
2 changes: 2 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4093,6 +4093,8 @@ def test_user_overview(self) -> None:
assert overview.num_upvotes > 10
assert len(overview.orgs) > 0
assert any(org.name == "huggingface" for org in overview.orgs)
assert overview.num_following > 300
assert overview.num_followers > 1000

def test_organization_members(self) -> None:
members = self.api.list_organization_members("huggingface")
Expand Down
Loading