Skip to content

[Python] - Support show function for DataFrame api of python library #941

@francis-du

Description

@francis-du

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
(This section helps Arrow developers understand the context and why for this feature, in addition to the what)

The current user who wants to preview the API of the DataFrame need to use the print function to print the result without limit after the collect. The printing result is very unfriendly. It is hoped that the user can print and preview the result of the DataFrame by calling one function.

import pyarrow as pa
from datafusion import ExecutionContext

ctx = ExecutionContext()

batch = pa.RecordBatch.from_arrays(
    [pa.array([1, 2, 3]), pa.array([4, 5, 6])],
    names=["a", "b"],
)

df = ctx.create_dataframe([[batch]])
for i in df.collect():
    for j in i:
        print(j)

Result

[
  1,
  2,
  3
]
[
  4,
  5,
  6
]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Let the user call the show function to print and preview the results, the user can customize the number of displayed lines, if not specified, 20 lines will be displayed by default.

eg:

import pyarrow as pa
from datafusion import ExecutionContext

ctx = ExecutionContext()

batch = pa.RecordBatch.from_arrays(
    [pa.array([1, 2, 3]), pa.array([4, 5, 6])],
    names=["a", "b"],
)

df = ctx.create_dataframe([[batch]])
df.show(10)

Result

+---+---+
| a | b |
+---+---+
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
+---+---+

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions