| 2597 | |
| 2598 | |
| 2599 | def test_table_repr_to_string(): |
| 2600 | # Schema passed explicitly |
| 2601 | schema = pa.schema([pa.field('c0', pa.int16(), |
| 2602 | metadata={'key': 'value'}), |
| 2603 | pa.field('c1', pa.int32())], |
| 2604 | metadata={b'foo': b'bar'}) |
| 2605 | |
| 2606 | tab = pa.table([pa.array([1, 2, 3, 4], type='int16'), |
| 2607 | pa.array([10, 20, 30, 40], type='int32')], schema=schema) |
| 2608 | assert str(tab) == """pyarrow.Table |
| 2609 | c0: int16 |
| 2610 | c1: int32 |
| 2611 | ---- |
| 2612 | c0: [[1,2,3,4]] |
| 2613 | c1: [[10,20,30,40]]""" |
| 2614 | |
| 2615 | assert tab.to_string(show_metadata=True) == """\ |
| 2616 | pyarrow.Table |
| 2617 | c0: int16 |
| 2618 | -- field metadata -- |
| 2619 | key: 'value' |
| 2620 | c1: int32 |
| 2621 | -- schema metadata -- |
| 2622 | foo: 'bar'""" |
| 2623 | |
| 2624 | assert tab.to_string(preview_cols=5) == """\ |
| 2625 | pyarrow.Table |
| 2626 | c0: int16 |
| 2627 | c1: int32 |
| 2628 | ---- |
| 2629 | c0: [[1,2,3,4]] |
| 2630 | c1: [[10,20,30,40]]""" |
| 2631 | |
| 2632 | assert tab.to_string(preview_cols=1) == """\ |
| 2633 | pyarrow.Table |
| 2634 | c0: int16 |
| 2635 | c1: int32 |
| 2636 | ---- |
| 2637 | c0: [[1,2,3,4]] |
| 2638 | ...""" |
| 2639 | |
| 2640 | |
| 2641 | def test_table_repr_to_string_ellipsis(): |