Skip to content

Commit 796eb5a

Browse files
Amrit02102004AmritSundarkaWauplin
authored
Fixed the issue #2535 Added user followers and following in class User and added test cases for it (#2536)
* Added user following and user followers in the user class * Added test cases to check for positive user followers and following * Update tests/test_hf_api.py --------- Co-authored-by: Amrit Sundarka <[email protected]> Co-authored-by: Lucain <[email protected]> Co-authored-by: Lucain <[email protected]>
1 parent a06e246 commit 796eb5a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,10 @@ class User:
14051405
Number of upvotes received by the user.
14061406
num_likes (`int`, *optional*):
14071407
Number of likes given by the user.
1408+
num_following (`int`, *optional*):
1409+
Number of users this user is following.
1410+
num_followers (`int`, *optional*):
1411+
Number of users following this user.
14081412
orgs (list of [`Organization`]):
14091413
List of organizations the user is part of.
14101414
"""
@@ -1423,6 +1427,8 @@ class User:
14231427
num_papers: Optional[int] = None
14241428
num_upvotes: Optional[int] = None
14251429
num_likes: Optional[int] = None
1430+
num_following: Optional[int] = None
1431+
num_followers: Optional[int] = None
14261432
orgs: List[Organization] = field(default_factory=list)
14271433

14281434
def __init__(self, **kwargs) -> None:
@@ -1439,6 +1445,8 @@ def __init__(self, **kwargs) -> None:
14391445
self.num_papers = kwargs.pop("numPapers", None)
14401446
self.num_upvotes = kwargs.pop("numUpvotes", None)
14411447
self.num_likes = kwargs.pop("numLikes", None)
1448+
self.num_following = kwargs.pop("numFollowing", None)
1449+
self.num_followers = kwargs.pop("numFollowers", None)
14421450
self.user_type = kwargs.pop("type", None)
14431451
self.orgs = [Organization(**org) for org in kwargs.pop("orgs", [])]
14441452

tests/test_hf_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,8 @@ def test_user_overview(self) -> None:
40934093
assert overview.num_upvotes > 10
40944094
assert len(overview.orgs) > 0
40954095
assert any(org.name == "huggingface" for org in overview.orgs)
4096+
assert overview.num_following > 300
4097+
assert overview.num_followers > 1000
40964098

40974099
def test_organization_members(self) -> None:
40984100
members = self.api.list_organization_members("huggingface")

0 commit comments

Comments
 (0)