In pandas < 3.0 without copy-on-write enabled, reset_index always creates a copy. This makes sense in pandas, as the pandas api has quite a few in-place methods
In the Narwhals API, we have zero in-place methods, so we can optimise maybe_reset_index by doing an early return of the object if:
the input object obj is a pandas-like dataframe or pandas_like series
the index idx is an instance of native_namespace.RangeIndex
idx.start == 0
idx.stop == len(obj) - 1
idx.step == 1
This should help with performance in the plotly PR
In pandas < 3.0 without copy-on-write enabled,
reset_index
always creates a copy. This makes sense in pandas, as the pandas api has quite a few in-place methodsIn the Narwhals API, we have zero in-place methods, so we can optimise
maybe_reset_index
by doing an early return of the object if:obj
is a pandas-like dataframe or pandas_like seriesidx
is an instance ofnative_namespace.RangeIndex
idx.start == 0
idx.stop == len(obj) - 1
idx.step == 1
This should help with performance in the plotly PR