You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds map.len() for expressions and Series backed by Polars 2.0 or newer. It counts the entries in each map, including entries with null values. Empty maps return 0, and null maps return null.
Codex helped with implementation and tests. GPT-6.2 Astra reviewed the patch.
Checklist
Code follows style guide (ruff)
Tests added
Documented the changes
Summary by CodeRabbit
New Features
Added map-length operations for series and expressions, returning the number of entries in each map as an unsigned 32-bit value. Null maps produce null results; null-valued entries are counted.
Map length is available with Polars 2.0 or newer.
Documentation
Updated the API reference to include map-length operations.
No actionable comments were generated in the recent review.
Walkthrough
The PR adds map-length methods to the series and expression APIs. Polars 2.0 or newer delegates the operation to its native map accessor. Other listed backends mark the operation as unsupported.
Changes: Map length API and backend support
Layer / File(s)
Summary
Public API and compliant expression path src/narwhals/series_map.py, src/narwhals/expr_map.py, src/narwhals/_compliant/any_namespace.py, src/narwhals/_compliant/expr.py, docs/api-reference/series_map.md, docs/api-reference/expr_map.md
Series and expression map namespaces add len(). The compliant namespace declares the operation, and the eager expression path delegates it. The API references list the new methods.
Backend support and validation src/narwhals/_polars/utils.py, src/narwhals/_arrow/series_map.py, src/narwhals/_duckdb/expr_map.py, src/narwhals/_ibis/expr_map.py, src/narwhals/_pandas_like/series_map.py, src/narwhals/_spark_like/expr_map.py, tests/expr_and_series/map/len_test.py
Polars checks for version 2.0 or newer before delegating map length to its native accessor. The other listed backends mark len as not implemented. Tests cover series, eager and lazy expressions, result dtypes, and unsupported cases.
This adds map.len() for Polars 2.0 or newer and marks it unsupported on other backends. No merge-blocking issue was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat: add map.len() for Polars" matches the main change. The PR adds a map.len() method to expressions and Series, backed by Polars 2.0 or newer. The diff also adds compliant, Arrow, DuckDB…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description states that the PR adds map.len() for expressions and Series backed by Polars 2.0 or newer, counts entries including null-valued ones, returns 0 for empty maps and null for null maps. …
Full details: Title check
Explanation
The title "feat: add map.len() for Polars" matches the main change. The PR adds a map.len() method to expressions and Series, backed by Polars 2.0 or newer. The diff also adds compliant, Arrow, DuckDB, Ibis, pandas-like, and Spark-like stubs that raise NotImplementedError. The title is specific and concise, and it follows the conventional commit style.
Full details: Description check
Explanation
The description states that the PR adds map.len() for expressions and Series backed by Polars 2.0 or newer, counts entries including null-valued ones, returns 0 for empty maps and null for null maps. It links related issue #4128, marks the Feature type, discloses AI assistance, and checks the Tests added and Documented the changes boxes. The template sections are all present and filled in, and the content matches the raw summary of changes.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: b9e64244-ec8d-4900-9630-cd625eb37a6a
Commits
Reviewing files that changed from the base of the PR and between 752fcd4 and 9b980b6.
Files selected for processing: 13
docs/api-reference/expr_map.md
docs/api-reference/series_map.md
src/narwhals/_arrow/series_map.py
src/narwhals/_compliant/any_namespace.py
src/narwhals/_compliant/expr.py
src/narwhals/_duckdb/expr_map.py
src/narwhals/_ibis/expr_map.py
src/narwhals/_pandas_like/series_map.py
src/narwhals/_polars/utils.py
src/narwhals/_spark_like/expr_map.py
src/narwhals/expr_map.py
src/narwhals/series_map.py
tests/expr_and_series/map/len_test.py
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
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
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.
Description
This PR adds
map.len()for expressions and Series backed by Polars 2.0 or newer. It counts the entries in each map, including entries with null values. Empty maps return0, and null maps return null.What type of PR is this? (check all applicable)
Related issues
mapnamespace operations #4128AI assistance
Codex helped with implementation and tests. GPT-6.2 Astra reviewed the patch.
Checklist
Summary by CodeRabbit