Description
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 am currently creating adapters so that my Qt-based UI (https://github.com/larray-project/larray-editor/) becomes a lot more generic instead of being only useful for our own project. The goal is to make it able to display any grid-like structure (arrays, dataframes, or even some files).
Please describe the purpose of the new feature or describe the problem to solve.
For obvious performance reasons, it is much faster to only compute what is actually visible on the screen, so my adapters try to do exactly that. I implemented that easily using the direct Polars API for both DataFrame and LazyFrame (and Ibis Table) with great result. However, when using the Narwhals Lazy API (on top of a Polars LazyFrame), I have not found any direct way to select specific rows other than top rows. I had to resort to an ugly workaround which works but makes things uncomfortably slow :
wh_index = data.with_row_index('_index')
filter_ = (nw.col('_index') >= v_start) & (nw.col('_index') < v_stop)
# .select also implicitly drops _index
lazy_sub_df = wh_index.filter(filter_).select(columns[h_start:h_stop])
I know of https://narwhals-dev.github.io/narwhals/basics/order_dependence/ and the fact that lazyFrame.tail() is deprecated but I would advocate for implementing slicing anyway. After all, even if one cannot guarantee the order (unless an explicit sort was used) and the order is arbitrary, it makes sense to paginate the result. Another argument is that all SQL engines I know of support some kind of offset command for pagination (whether via limit/offset or offset fetch which is standard SQL AFAIK). Some SQL engine require sorting, for offset to work, but in my (limited) experience this is rather the exception than the rule.
Suggest a solution if possible.
One option might be to allow slicing only if the query includes a sort operation. It would not help my specific case though.
If you have tried alternatives, please describe them below.
No response
Additional information that may help us understand your needs.
No response