Add polars/narwhals support to the formula interface#502
Merged
Martin Stancsics (stanmart) merged 13 commits intomainfrom Jan 13, 2026
Merged
Add polars/narwhals support to the formula interface#502Martin Stancsics (stanmart) merged 13 commits intomainfrom
Martin Stancsics (stanmart) merged 13 commits intomainfrom
Conversation
1 task
Marc-Antoine Schmidt (MarcAntoineSchmidtQC)
approved these changes
Jan 9, 2026
Member
Marc-Antoine Schmidt (MarcAntoineSchmidtQC)
left a comment
There was a problem hiding this comment.
Look's good. I tested the speed and nw.from_native is always extremely fast, although faster for polars. But this is not going to be relevant in any of our benchmarks.
Copilot started reviewing on behalf of
Martin Stancsics (stanmart)
January 12, 2026 08:23
View session
There was a problem hiding this comment.
Pull request overview
This PR adds support for polars and other dataframes supported by narwhals to the formula interface, building on previous work. It updates the Python requirement from 3.9 to 3.10 and upgrades the formulaic dependency from 0.6 to 1.2.
Changes:
- Integrated narwhals for generic dataframe support in
TabmatMaterializerandencode_contrasts - Refactored
_InteractableCategoricalVector.from_categoricaltofrom_codesfor framework-agnostic categorical handling - Added comprehensive test parametrization to run all formula tests with both pandas and polars dataframes
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_formula.py | Parametrized all formula tests to run with both pandas and polars; updated fixtures to support multiple input types; updated categorical vector creation to use new from_codes API |
| src/tabmat/formula.py | Added narwhals integration to TabmatMaterializer; refactored categorical handling to use codes/categories instead of pandas-specific objects; updated _C and encode_contrasts functions for generic dataframe support |
| src/tabmat/categorical_matrix.py | Added support for polars Enum types in _extract_codes_and_categories_polars |
| src/tabmat/benchmark/generate_matrices.py | Added type ignore comment for type checking |
| setup.py | Removed Python 3.9 support, updated formulaic requirement to >=1.2, bumped minimum Python to 3.10 |
| pyproject.toml | Updated mypy python_version from 3.9 to 3.10 |
| pixi.toml | Updated Python requirements, formulaic version, polars version, removed py39 environment |
| conda.recipe/meta.yaml | Updated formulaic requirement to >=1.2 |
| CHANGELOG.rst | Documented new narwhals/polars support and Python 3.10 requirement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This PR follows up on #370 and #388 by adding generic dataframs support for the formula interface.
Checklist
CHANGELOG.rstentry