Skip to content

Make to_string match pandas (drop repr-style truncation/footer) - #22929

Merged
rapids-bot[bot] merged 5 commits into
NVIDIA:mainfrom
galipremsagar:cudf_to_string_match_pandas
Jun 24, 2026
Merged

Make to_string match pandas (drop repr-style truncation/footer)#22929
rapids-bot[bot] merged 5 commits into
NVIDIA:mainfrom
galipremsagar:cudf_to_string_match_pandas

Conversation

@galipremsagar

Copy link
Copy Markdown
Contributor

Description

Makes Series.to_string() / DataFrame.to_string() match pandas, fixing the cudf.pandas failures in tests/io/formats/test_to_string.py (16 cases).

Previously cuDF's to_string was just str(self) (i.e. repr), so it took no arguments, truncated based on display.max_rows/display.max_columns, rendered nulls as <NA>, and appended a dtype/name/length footer. pandas' to_string does none of these by default and accepts a rich set of formatting arguments.

IndexedFrame.to_string now accepts the pandas signature and delegates to pandas' formatter (self.to_pandas().to_string(*args, **kwargs)), so cuDF prints identically to pandas — as the docstring already promised.

Behavior change

to_string() no longer truncates based on the display.max_rows/display.max_columns options (use the max_rows/max_cols arguments, matching pandas) and no longer appends the dtype/name/length footer or renders nulls as <NA> by default. repr / __repr__ are unchanged, so interactive display still truncates and shows the footer as before.

cuDF tests that encoded the old repr-style to_string output are updated to the pandas-matching behavior (passing max_rows/max_cols explicitly where truncation is intended), and two tests are added to lock in the new contract (test_to_string_ignores_display_options, test_series_to_string_no_dtype_footer). The now-passing test_to_string.py xfail entries are removed from the cudf.pandas plugin.

Verification

  • pandas test_to_string.py under cudf.pandas (with plugin): 93 passed, 1 xfailed, 0 failed, 0 XPASS.
  • cuDF to_string + repr unit suites: pass (repr unchanged).
  • Broad regression across all dataframe/series methods + other to_string callers: 12496 passed, 0 failed.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@galipremsagar
galipremsagar requested a review from a team as a code owner June 19, 2026 04:20
@github-actions github-actions Bot added Python Affects Python cuDF API. cudf.pandas Issues specific to cudf.pandas labels Jun 19, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jun 19, 2026
@galipremsagar galipremsagar added bug Something isn't working non-breaking Non-breaking change labels Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 86345bd4-2580-41e0-b382-43a439d0f523

📥 Commits

Reviewing files that changed from the base of the PR and between e6e682a and 3acf2cc.

📒 Files selected for processing (2)
  • python/cudf/cudf/core/dataframe.py
  • python/cudf/cudf/core/series.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • python/cudf/cudf/core/series.py
  • python/cudf/cudf/core/dataframe.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added pandas-compatible to_string() to both DataFrame and Series, including support for common formatting and display-control options (and correct buf behavior).
  • Tests
    • Updated and refactored to_string() expectations to be generated from pandas, added coverage that cudf.to_string() ignores pandas display limits, verified Series output has no dtype footer by default, and refreshed IO/compression expected-failure annotations.
  • Chores
    • Updated SPDX copyright headers.

Walkthrough

IndexedFrame.to_string is removed; DataFrame.to_string and Series.to_string are added with full pandas parameter support and pandas delegation. Tests are refactored to pass truncation arguments explicitly and compute expected output from pandas; expected-failure entries are updated.

Changes

DataFrame and Series to_string pandas delegation

Layer / File(s) Summary
DataFrame and Series to_string implementations
python/cudf/cudf/core/indexed_frame.py, python/cudf/cudf/core/dataframe.py, python/cudf/cudf/core/series.py
IndexedFrame.to_string base implementation is removed. DataFrame.to_string is added with full pandas parameter set (formatting, truncation, layout options) and delegates to self.to_pandas().to_string(). Series.to_string is added with pandas Series parameters and same delegation pattern. Copyright headers updated.
Test refactor and behavioral validation
python/cudf/cudf/tests/dataframe/methods/test_to_string.py, python/cudf/cudf/tests/series/methods/test_to_string.py
Existing DataFrame and Series to_string tests are refactored to pass max_rows/max_cols directly to cudf and compute expected output via to_pandas().to_string(). Two new DataFrame tests are added asserting display-option independence and dtype footer absence. Series init-None test switches from repr() to to_string() for output comparison. Copyright headers updated.
Expected-failure metadata updates
python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
Removes AssertionError-based expected-failure entries for test_to_string.py cases that no longer apply. Adds three test_to_csv.py::TestToCSV entries with TODO placeholder reasons. Removes test_to_string_index_with_nan expected-failure entry. Updates test_with_s3_url expected-failure reasons to reference moto server requirement at http://localhost:5000.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

improvement

Suggested reviewers

  • mroeschke
  • vyasr
  • rjzamora
  • brandon-b-miller
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: making to_string match pandas behavior by dropping repr-style truncation and footer functionality.
Description check ✅ Passed The description comprehensively explains the changes, behavioral impacts, rationale, and includes verification results that align with the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Comment thread python/cudf/cudf/core/indexed_frame.py Outdated
@galipremsagar
galipremsagar requested a review from mroeschke June 23, 2026 22:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cudf/cudf/core/series.py`:
- Around line 852-871: The docstring for the Series.to_string method is
incomplete and does not document the parameters (such as buf, max_rows, etc.) or
return value semantics. Add a Parameters section listing all accepted arguments
and their descriptions, including clarification that the buf parameter controls
whether the method returns a string or None. Add a Returns section documenting
the return type and behavior, explicitly noting that when buf is provided, the
method returns None, and when buf is None (the default), it returns a formatted
string. Ensure the docstring follows pandas-style documentation conventions to
maintain consistency with the codebase.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 90d8b2e4-dc39-4d69-b948-3206e0042ccf

📥 Commits

Reviewing files that changed from the base of the PR and between 656f672 and e6e682a.

📒 Files selected for processing (6)
  • python/cudf/cudf/core/dataframe.py
  • python/cudf/cudf/core/indexed_frame.py
  • python/cudf/cudf/core/series.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
  • python/cudf/cudf/tests/dataframe/methods/test_to_string.py
  • python/cudf/cudf/tests/series/methods/test_to_string.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/core/indexed_frame.py
✅ Files skipped from review due to trivial changes (1)
  • python/cudf/cudf/tests/series/methods/test_to_string.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • python/cudf/cudf/tests/dataframe/methods/test_to_string.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py

Comment thread python/cudf/cudf/core/series.py
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/merge

@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label Jun 24, 2026
@rapids-bot
rapids-bot Bot merged commit fcb2681 into NVIDIA:main Jun 24, 2026
126 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jun 24, 2026
mhaseeb123 pushed a commit to mhaseeb123/cudf that referenced this pull request Jun 24, 2026
…IDIA#22929)

Makes `Series.to_string()` / `DataFrame.to_string()` match pandas, fixing the `cudf.pandas` failures in `tests/io/formats/test_to_string.py` (16 cases).

Previously cuDF's `to_string` was just `str(self)` (i.e. `repr`), so it took no arguments, truncated based on `display.max_rows`/`display.max_columns`, rendered nulls as `<NA>`, and appended a `dtype`/`name`/`length` footer. pandas' `to_string` does none of these by default and accepts a rich set of formatting arguments.

`IndexedFrame.to_string` now accepts the pandas signature and delegates to pandas' formatter (`self.to_pandas().to_string(*args, **kwargs)`), so cuDF prints identically to pandas — as the docstring already promised.

### Behavior change
`to_string()` no longer truncates based on the `display.max_rows`/`display.max_columns` options (use the `max_rows`/`max_cols` arguments, matching pandas) and no longer appends the `dtype`/`name`/`length` footer or renders nulls as `<NA>` by default. `repr` / `__repr__` are unchanged, so interactive display still truncates and shows the footer as before.

cuDF tests that encoded the old repr-style `to_string` output are updated to the pandas-matching behavior (passing `max_rows`/`max_cols` explicitly where truncation is intended), and two tests are added to lock in the new contract (`test_to_string_ignores_display_options`, `test_series_to_string_no_dtype_footer`). The now-passing `test_to_string.py` xfail entries are removed from the cudf.pandas plugin.

### Verification
- pandas `test_to_string.py` under cudf.pandas (with plugin): 93 passed, 1 xfailed, 0 failed, 0 XPASS.
- cuDF `to_string` + repr unit suites: pass (repr unchanged).
- Broad regression across all dataframe/series methods + other `to_string` callers: 12496 passed, 0 failed.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: NVIDIA#22929
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working cudf.pandas Issues specific to cudf.pandas non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants