Repository navigation
Conversation
solegalli
force-pushed
the
narwhals-expanding-window-features
branch
from
November 21, 2026 09:27
e20de4c to
8c2e063
Compare
solegalli
changed the base branch from
narwhals-migration
to
narwhals-window-features
November 21, 2026 09:27
solegalli
force-pushed
the
narwhals-window-features
branch
from
November 25, 2026 18:58
b793d2b to
c354c6c
Compare
Base automatically changed from
narwhals-window-features
to
narwhals-migration
November 26, 2026 15:02
pandas keeps its expanding().agg().shift() path. With polars, the features are built with narwhals rolling and cumulative expressions, and the polars rolling median, and give the same values as pandas. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With polars, ExpandingWindowFeatures now takes the 15 pandas expanding functions that aggregate one variable: first, last, nunique and sem with narwhals, and skew, kurt and rank with polars, as median. __init__ validates min_periods and sort_index, rejects periods=True, and its messages end with "Got ... instead.". The helpers have no early returns, and the functions check is shared with WindowFeatures. The tests check the column order and drop_original with drop_na on both libraries, and the user guide shows the feature names before the polars section, which redefined X. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
solegalli
force-pushed
the
narwhals-expanding-window-features
branch
from
November 26, 2026 15:17
8c2e063 to
e429e28
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExpandingWindowFeaturesnow takes pandas and polars dataframes.What changes
expanding(min_periods).agg(functions).shift(periods, freq), merged on the index.periodsrows:sum,mean,std,varandsemuse narwhals' rolling expressions, with a window as long as the dataframe;count,min,max,first,lastandnuniqueuse cumulative narwhals expressions;median,skew,kurtandrankuse polars' own rolling functions, because narwhals has none;missing_values="ignore", NaN and inf are missing data, as in pandas.fit: other functions raiseNotImplementedError, asfreqdoes. The check is shared withWindowFeatures.add_expanding_window_features, intimeseries/forecasting/_forecasting_helpers.py.Behaviour changes
__init__now rejects:min_periods, or one that isn't an integer;functions=[]or"";periods=True;sort_indexthat isn'tTrueorFalse.The error messages end with "Got ... instead.". The
functionsmessage had a missing space, and the duplicated functions message changes.With pandas,
corrandcovstill run as onmain: they aren't single-variable aggregations, so they aren't documented.User guide: fixed a missing bracket and
period=1(nowperiods), and moved "Getting the name of the new features" before the polars section, which redefinedX.Checks
narwhals-migrationin 178 pandas cases, on pandas 3 and 2.3. Identical to the previous version of this PR in 266 cases on pandas and polars, except the 16 polars cases with the new functions, which used to raise. This coverstransform,transform_x_y,get_feature_names_out, reordered columns, shuffled rows and missing data.min_periodsNone, 0, 1, 2, 5 and 100,periods0, 1 and 3, NaN and inf.narwhals-migration. flake8 is clean, and mypy shows only the knowndatetime_subtraction.pyerror.main's tests pass, except 3 that compare the old error messages.fit+transform, 2M × 5, in ms:The functions polars already had run as fast as in the previous version of this PR.
Needs decision
WindowFeatures:min_samples=needs polars 1.21 andrankneeds 1.35, whilepyproject.tomlasks forpolars>=1.0.0.Open
skew0 andkurt-3, and polars gives NaN, as inWindowFeatures.skewandkurtare about 2x slower than pandas, which updates running moments instead of using a long rolling window.first,lastandnuniquedon't exist, andsemdivides by √(n − 1). The tests skip them there.median,skew,kurtandrankcall polars functions, so other libraries that narwhals supports, like modin, would fail on them intransform.transform_x_ywith the target as a list or an array waits for the fix infix-transform-xy-targets.