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

✨ Recursively query parents and children #2106

Merged
merged 5 commits into from
Oct 24, 2024
Merged

✨ Recursively query parents and children #2106

merged 5 commits into from
Oct 24, 2024

Conversation

Koncopd
Copy link
Member

@Koncopd Koncopd commented Oct 23, 2024

This PR adds query_parents and query_children methods to HasParents class. This allows to query all parents and parents of parents etc. recursively for all records that have parents (instances of subclasses of HasParents).

Example:

import lamindb as ln

label1 = ln.ULabel(name="label1")
label2 = ln.ULabel(name="label2")
label3 = ln.ULabel(name="label3")
label1.save()
label2.save()
label3.save()
label1.children.add(label2)
label2.children.add(label3)
label3.query_parents() # returns a QuerySet with label1 and label2
label1.query_children() # returns a QuerySet with label2 and label3

Closes #2060

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.53%. Comparing base (c41fc2c) to head (1ab7f1a).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2106   +/-   ##
=======================================
  Coverage   92.52%   92.53%           
=======================================
  Files          54       54           
  Lines        6435     6442    +7     
=======================================
+ Hits         5954     5961    +7     
  Misses        481      481           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Oct 23, 2024

@github-actions github-actions bot temporarily deployed to pull request October 23, 2024 15:41 Inactive
@falexwolf
Copy link
Member

This looks very elegant both in terms of the actual implementation and the user-facing API design. Kudos!

The only thing that's missing: a nice user-facing description of this PR.

@Koncopd
Copy link
Member Author

Koncopd commented Oct 24, 2024

Ok, adding and merging then.

@github-actions github-actions bot temporarily deployed to pull request October 24, 2024 09:37 Inactive
@Koncopd Koncopd merged commit 8447000 into main Oct 24, 2024
16 checks passed
@Koncopd Koncopd deleted the get_parents branch October 24, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function to recursively filter parents/children
2 participants