.over
for pandas is implemented via groupby operation, in which we only support elementary expressions (as we want to avoid running .groupby(...).apply(...)
for the user).
One workaround is to split it into two chained over
statements:
(
pd_df
.with_columns(x = nw.col('x').cum_sum().over('group'))
.with_columns(x = nw.col('x').shift(1).over('group'))
)
I am not sure we will be able to support complex expressions.
linking because the tag doesn't exist on stackoverflow yet
Fun fact: SO doesn't let me create a narwhals
tag as there is a narwhal
one and they are too similar. Should I create python-narwhals
?