Open FBruzzesi opened 1 week ago
Interesting thanks - how do skrub use mode?
Ok, I don't know if this is good, or bad, or what... but... if the values are not numeric and the group is multi-modal, then we get a list in pandas as well:
data = {
"g1": [1, 1, 1, 1],
"x1": ["x", "x", "y", "z"],
"x2": ["a", "a", "b", "b"],
}
(pd.DataFrame(data)
.groupby("g1")
.agg(
x1=("x1", pd.Series.mode),
x2=("x2", pd.Series.mode)
)
)
x1 x2
g1
1 x [a, b]
but it would still not be supported in narwhals, since it has to use pd.Series.mode
or we need to return a scalar value from Expr.mode
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?
mode
operation in group by context behave very differently across pandas, polars and pyarrow.As for when
mode
was introduced, I am taking a mild look at skrub usecase.Please describe the purpose of the new feature or describe the problem to solve.
Consider the following snippet:
Polars
Polars has a consistent behavior and, even if the column is unimodal, it will return a
list[T]
pandas
pandas fails for multi-modal results as it would not return a scalar.
pyarrow
I was not able to find a way to have the mode value directly
Suggest a solution if possible.
Unsure on how to proceed
If you have tried alternatives, please describe them below.
No response
Additional information that may help us understand your needs.
No response