-
Notifications
You must be signed in to change notification settings - Fork 92
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
[Enh]: Ability to use nw.col
/ Expr
for .group_by
#1385
Comments
Thanks for the request! Just to make sure I've understood - you want to be able to do |
Yes that is correct. I'd like to be able to do this in order to be able to differentiate various queries a user would perform on an AnnData structure. You could think of it as multiple DataFrames stuck together. Currently I have different "columns" associated to a particular DataFrame. For example a column for the Variables DataFrame is a callable class These are classes which wrap the functionality of Other Narwhals methods such as If I just use strings then I'd have to create separate logic different than using methods such as Heres an example of what I'm able to do with thisimport annsel as an
# assume we have some AnnData object
adata.an.filter(
an.obs_col(["Cell_label"] == "Lymphomyeloid prog",
an.var_col(["feature_type"]).is_in(["protein_coding", "lncRNA"]))
) Here I am filtering the Observation DataFrame based on Because I hope this helps clarify why this feature would be useful for me. |
We would like to learn about your use case. For example, if this feature is needed to adopt Narwhals in an open source project, could you please enter the link to it below?
I'm writing a
groupby
method forannsel
where we can group by one, or both of the following dataframes in the AnnData object: Variables (var) and Observations (obs).Please describe the purpose of the new feature or describe the problem to solve.
I currently have both filtering and selecting which both make use of classes with respect to the dataframe where the query is being applied to. These wrap and return
nw.col
Expressions. These work, but withgroup_by
it only expects strings. It would be nice if I could usenw.col(*names)
.For example:
gives me the the following error:
TypeError of
'Expr'
object is not callableThis would help me keep my internal API consistent.
Suggest a solution if possible.
Maybe a special case fornw.col
? Or a way to make it a hashable perhaps?Perhaps a solution is to make
nw.col
an instantiation of it's own classCol
such as howPolars
does it.If you have tried alternatives, please describe them below.
The alternative that I've tried is to strictly use strings, which works, but isn't ideal.
Additional information that may help us understand your needs.
Here is some additional context to my workflow.
I then run a match-case against the
Expr
subtype and collect those forvar
,obs
and other DataFrames within AnnData. Depending on the operation some get executed on their respective DataFrame.The text was updated successfully, but these errors were encountered: