Skip to content

Add dataframe-agnostic mini-batch support with Narwhals #153

Description

@kulbachcedric

River is migrating its mini-batch methods to Narwhals so that pandas, Polars, PyArrow, and other supported eager dataframe backends can be used while preserving the caller's native backend.

Deep-river's current mini-batch paths are pandas-specific and directly use pd.DataFrame, pd.Series, .values, .index, and pandas output constructors.

Proposed scope

Start with the main supervised estimators and shared conversion boundary:

  • deep_river.classification.Classifier
  • deep_river.regression.Regressor
  • Shared dataframe-to-tensor utilities

The implementation should:

  • Accept Narwhals-supported dataframe and series inputs.
  • Convert inputs to NumPy only at the tensor boundary.
  • Return predictions in the same backend as the input.
  • Preserve the pandas index.
  • Keep existing pandas behavior unchanged.
  • Support reordered, emerging, and disappearing features.

Deep-river currently supports river>=0.25,<0.26, while the dataframe helpers on River's main branch are not part of River 0.25. The initial implementation should therefore use a small internal boundary utility and a direct Narwhals dependency instead of importing unreleased River helpers.

Autoencoders, multi-target estimators, and rolling estimators can be migrated in follow-up changes once the shared approach is established.

Tests

Add cross-backend tests covering:

  • pandas, Polars, and PyArrow
  • Prediction parity between backends
  • Backend-preserving return types
  • pandas index preservation
  • Reordered columns
  • Emerging and disappearing features
  • Missing values

Related upstream work

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions