laminlabs / lamindb

A data framework for biology.
https://docs.lamin.ai
Apache License 2.0
129 stars 12 forks source link

✨ Recursively query parents and children #2106

Closed Koncopd closed 1 month ago

Koncopd commented 1 month ago

This PR adds query_parents and query_children methods to the HasParents class. This allows to query all parents and parents of parents etc. recursively for a record.

Example:

import lamindb as ln

label1 = ln.ULabel(name="label1").save()
label2 = ln.ULabel(name="label2").save()
label3 = ln.ULabel(name="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

Docs:

Resolves:

Needs:

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 1 month ago

🚀 Deployed on https://671a154e02dcafae9d3ac8eb--lamindb-qnwk.netlify.app

falexwolf commented 1 month ago

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 commented 1 month ago

Ok, adding and merging then.