feat: make obs/var backend-agnostic with a DataFrameLike contract#2516
Open
srivarra wants to merge 4 commits into
Open
feat: make obs/var backend-agnostic with a DataFrameLike contract#2516srivarra wants to merge 4 commits into
srivarra wants to merge 4 commits into
Conversation
Using narwhals as the conversion layer between DataFrame implementations, makes Dataset2D "dataframe-like" in the eyes of narwhals. Signed-off-by: Sricharan Reddy Varra <sricharanvarra@gmail.com>
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2516 +/- ##
==========================================
- Coverage 87.66% 85.66% -2.01%
==========================================
Files 49 50 +1
Lines 7729 7797 +68
==========================================
- Hits 6776 6679 -97
- Misses 953 1118 +165
|
Signed-off-by: Sricharan Reddy Varra <sricharanvarra@gmail.com>
Signed-off-by: Sricharan Reddy Varra <sricharanvarra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using narwhals as the conversion layer between DataFrame implementations, and makes Dataset2D "dataframe-like" in the eyes of narwhals.
DataFrameAPI forobsandvarkeys via runtime-checkableProtocol#2043I built a thin narwhals translation layer between
AnnData.obs/AnnData.varand the DataFrame backends narwhals supports. Now.obs/.varaccept a Polars DataFrame, among others; cuDF should work too, though I haven't tested it.The
DataFrameLikecontract comes from #2328. A small narwhals plugin converts aDataset2Dto any other DataFrame: it materializes theDataset2Din-memory as a pandas df, which narwhals knows how to handle. Therefore it stops being lazy... there may be a way to keep the laziness as narwhals has lazy backends such as Dask and Polars'LazyDataFrame, but I haven't looked into that yet.I also added a couple of convenience methods,
AnnData.obs_as(...)andAnnData.var_as(...), where you can convert it to another eager DataFrame type (Pandas, Polars, Modin, cuDF, pyarrow). We can discuss if that's the right approach or not.I've deferred the concat and merge API for now, we could try to find a way to add it here or leave it for later.
I remember I saw something in the scverse zulip about documenting if AI was used for PRs but I'm not sure if it's in PR templates. I did use AI throughout the process for this PR.
Remaining TODOS: