Commit ef10ac9
[Data] Improve appearance of repr(dataset) (#59631)
## Description
improve the UX by making this look like polars when using Ray Dataset.
#### test demo
```python
>>> import numpy as np
>>> import ray
>>> from ray.data import DataContext
ray.init(include_dashboard=False, ignore_reinit_error=True)
>>>
>>> ray.init(include_dashboard=False, ignore_reinit_error=True)
2025-12-25 03:38:11,358 INFO worker.py:2010 -- Started a local Ray instance.
/Users/xxx/work/community/ray/python/ray/_private/worker.py:2049: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0
warnings.warn(
RayContext(dashboard_url='', python_version='3.10.19', ray_version='3.0.0.dev0', ray_commit='{{RAY_COMMIT_SHA}}')
# Configure truncation: show 4 rows total (1 from the head, the rest from the tail)
# and display up to 5 columns (2 from the head, 2 from the tail, plus an ellipsis).
>>> ctx = DataContext.get_current()
>>> ctx.dataset_repr_max_rows = 4 # Display a total of 4 rows
>>> ctx.dataset_repr_head_rows = 1 # To display 1 row from the head and the remaining from the tail
>>> ctx.dataset_repr_max_columns = 5 # Show 5 columns in total, with middle columns truncated (represented by ellipsis ...).
>>> ctx.dataset_repr_head_columns = 2 # Display the first 2 columns at the head, and the remaining columns at the tail
# Create a demo dataset with 10 rows and 6 columns.
>>> items = [
... {f"col{i}": i + row for i in range(6)}
... for row in range(10)
... ]
>>> ds = ray.data.from_items(items)
>>>
>>> print("Before materialization (schema preview only):")
Before materialization (schema preview only):
>>> print(ds)
shape: (10, 6)
╭───────┬───────┬─────┬───────┬───────╮
│ col0 ┆ col1 ┆ … ┆ col4 ┆ col5 │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ int64 ┆ int64 ┆ … ┆ int64 ┆ int64 │
╰───────┴───────┴─────┴───────┴───────╯
(Showing 0 of 10 rows)
(Showing 4 of 6 columns)
>>> print("\nAfter materialization (shows head/tail rows):")
After materialization (shows head/tail rows):
>>> print(ds.materialize()) # To display a head/tail summary of 4 rows with truncated columns/ellipsis in a tabular format
shape: (10, 6)
╭───────┬───────┬─────┬───────┬───────╮
│ col0 ┆ col1 ┆ … ┆ col4 ┆ col5 │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ int64 ┆ int64 ┆ … ┆ int64 ┆ int64 │
╞═══════╪═══════╪═════╪═══════╪═══════╡
│ 0 ┆ 1 ┆ … ┆ 4 ┆ 5 │
│ … ┆ … ┆ … ┆ … ┆ … │
│ 7 ┆ 8 ┆ … ┆ 11 ┆ 12 │
│ 8 ┆ 9 ┆ … ┆ 12 ┆ 13 │
│ 9 ┆ 10 ┆ … ┆ 13 ┆ 14 │
╰───────┴───────┴─────┴───────┴───────╯
(Showing 4 of 10 rows)
(Showing 4 of 6 columns)
```
## Related issues
> Link related issues: #59482
Fixes #59482
---------
Signed-off-by: yaommen <myanstu@163.com>
Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Co-authored-by: Balaji Veeramani <bveeramani@berkeley.edu>1 parent 390ae76 commit ef10ac9
File tree
15 files changed
+864
-276
lines changed- doc/source/data
- python/ray
- data
- _internal
- tests
- datasource
- unit
- train
- tests
15 files changed
+864
-276
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
403 | 409 | | |
404 | 410 | | |
405 | 411 | | |
| |||
414 | 420 | | |
415 | 421 | | |
416 | 422 | | |
417 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
418 | 436 | | |
419 | 437 | | |
420 | 438 | | |
| |||
427 | 445 | | |
428 | 446 | | |
429 | 447 | | |
430 | | - | |
| 448 | + | |
431 | 449 | | |
432 | 450 | | |
433 | 451 | | |
434 | 452 | | |
435 | 453 | | |
436 | 454 | | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
442 | 466 | | |
443 | 467 | | |
444 | 468 | | |
| |||
460 | 484 | | |
461 | 485 | | |
462 | 486 | | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
468 | 498 | | |
469 | 499 | | |
470 | 500 | | |
| |||
485 | 515 | | |
486 | 516 | | |
487 | 517 | | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
493 | 529 | | |
494 | 530 | | |
495 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
0 commit comments