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
{{ message }}
Repository navigation
fix: return null for modulo by zero on pandas-like backends (#4036) - #4062
PR #4011 updated // 0 to return null on pandas-like backends via floordiv_null_on_zero. However, % was still using the raw operator, returning 0 for nullable integer dtypes (e.g. Int64, Int32, UInt32), whereas other backends return null.
This PR:
Introduces mod_null_on_zero in src/narwhals/_pandas_like/utils.py and routes __mod__ / __rmod__ through it in src/narwhals/_pandas_like/series.py.
Preserves native nullable integer dtypes while ensuring division/modulo by zero safely returns null (<NA>).
Adds dedicated unit tests in tests/expr_and_series/division_by_zero_test.py across nullable integer types (Int64, Int32, Int8, UInt32) for both scalar and column operands.
Summary by CodeRabbit
Bug Fixes
Modulo operations now return null results when the divisor is zero, including reflected operations and expressions.
Results preserve the input dtype in supported pandas-like backends.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 61faf724-18e2-428f-84ec-16dfa9895b62
📥 Commits
Reviewing files that changed from the base of the PR and between 4d6f7b0 and 0297c20.
📒 Files selected for processing (3)
src/narwhals/_pandas_like/series.py
src/narwhals/_pandas_like/utils.py
tests/expr_and_series/division_by_zero_test.py
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
📝 Walkthrough
Walkthrough
The pandas-like backend now applies null-on-zero handling to modulo operations. Tests cover scalar and column divisors, reflected operations, expressions, and dtype preservation.
No identified issue blocks merging; run the normal test checks before merge.
Pre-merge checks | 4 | 1
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 3 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name
Status
Explanation
Title check
The title clearly and concisely identifies the main fix: returning null for modulo-by-zero on pandas-like backends.
Description check
The description explains the issue, the implementation, the affected dtypes, and the added test coverage. It includes a related issue reference but does not complete the template checkboxes for PR typ…
Linked Issues check
Issue #4036 requires null results for modulo by zero on pandas-like nullable integer data, for both operand orders and scalar or zero-valued column divisors. The PR adds _null_on_zero and `mod_null_…
Out of Scope Changes check
The changed source files implement the modulo-by-zero behavior from issue #4036. The added tests verify the requested scalar, column, reflected, mixed-divisor, null-scalar, and dtype cases. No unrelat…
Fix all pre-merge checks with AI
✨ 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.
Comment @coderabbitai help to get the list of available commands.
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.
Fixes #4036.
Description
PR #4011 updated
// 0to return null on pandas-like backends viafloordiv_null_on_zero. However,%was still using the raw operator, returning0for nullable integer dtypes (e.g.Int64,Int32,UInt32), whereas other backends return null.This PR:
mod_null_on_zeroinsrc/narwhals/_pandas_like/utils.pyand routes__mod__/__rmod__through it insrc/narwhals/_pandas_like/series.py.<NA>).tests/expr_and_series/division_by_zero_test.pyacross nullable integer types (Int64,Int32,Int8,UInt32) for both scalar and column operands.Summary by CodeRabbit