Repository navigation
fix: return empty strings from str.tail(0) - #4120
Mike-Animal-Counseling wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Zero-length tail behavior and tests src/narwhals/expr_str.py, src/narwhals/series_str.py, tests/expr_and_series/str/tail_test.py |
Both methods pass a slice length of zero when n=0 and document this behavior. Tests cover n values 0, 1, 3, and 10 for expressions and eager series. |
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested labels: fix, tests, documentation
Suggested reviewers: marcogorelli, fbruzzesi
Merge Risk: 
Minimal · up to d80bc
-
No merge-blocking issue is identified in the zero-length tail fix. The change appears ready to merge subject to normal checks.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.
-
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.
Description
Expr.str.tail(0)andSeries.str.tail(0)return the entire input string instead of an empty string. This affects every backend because the public accessors translate zero intostr.slice(offset=0, length=None). Code that computes the requested suffix length can therefore receive the entire value when the length is zero.Pass
length=0for this case, retaining the existing translation for all nonzero values. This matches native Polars and preserves null values. No backend implementation, public signature, or runtime dependency changes are needed. The shared fix also applies to the stable namespaces.The parametrized regression tests cover zero, one, an ordinary suffix length, and a length larger than the input, including Unicode, empty strings, and nulls. With the tests added to the original source, the zero cases fail across all ten selected constructors: 15 failed, 45 passed. With the fix, the tail/head/slice tests give 195 passed.
What type of PR is this? (check all applicable)
Related issues
No existing issue is claimed as resolved. Searched existing issues, PRs and history for
tail; #1789 concerns the API completeness tables, and #3969 concernsstr.sliceboundaries.Validation
Windows, CPython 3.12.10, dependencies from the unchanged lockfile. Since
makeis unavailable, the underlying Makefile commands were run with the project virtual environment.prek run --all-files: all hooks passed.mypy: no issues in 485 source files.pyright --pythonpath <project>/.venv/Scripts/python.exe: 0 errors, 0 warnings.pyrefly check: 0 errors (existing suppressed diagnostics retained).python -m pytest src --doctest-modules -q: 486 passed.ciprofile, which is selected automatically in upstream CI. Initial local runs with the default profile hit timing/slow-input health checks; the CI profile keeps the same sample count and assertions, uses deterministic inputs, and disables timing checks. No repository test configuration was changed.python -m pytest tests --cov=src --cov=tests --cov-fail-under=95 --runslow \ --hypothesis-profile=ci --numprocesses=4 \ --constructors='pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb,sqlframe'zensical build --clean --strictpassed. The initial sandboxed build could not download Python's cross-reference inventory; it passed after network access was restored, without configuration changes.AI assistance
OpenAI Codex (GPT-6 based agent) assisted with investigation, implementation, regression tests, validation and drafting this description. The submitting author must review and take responsibility for the diff and the description.
Checklist
pytestpassing locally (not CI).Screenshot of the actual local pytest log displayed in a browser (not a CI result):
Summary by CodeRabbit
tailoperations withn=0now return an empty string for each non-null value.