Skip to content

Commit 625a1f2

Browse files
committed
feat: Add DataframeDisplayConfig class for customizable DataFrame display options
- Introduced DataframeDisplayConfig to manage display settings for DataFrames. - Added properties for max_table_bytes, min_table_rows, max_cell_length, and max_table_rows_in_repr. - Each property includes getter and setter methods for easy configuration. - Default values provided for each parameter to enhance usability.
1 parent 07d7cf6 commit 625a1f2

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

python/datafusion/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
RuntimeEnvBuilder,
3939
SessionConfig,
4040
SessionContext,
41+
DataframeDisplayConfig,
4142
SQLOptions,
4243
)
4344
from .dataframe import DataFrame
@@ -70,6 +71,7 @@
7071
"ScalarUDF",
7172
"SessionConfig",
7273
"SessionContext",
74+
"DataframeDisplayConfig",
7375
"Table",
7476
"WindowFrame",
7577
"WindowUDF",

python/datafusion/context.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,75 @@ class TableProviderExportable(Protocol):
7979
def __datafusion_table_provider__(self) -> object: ... # noqa: D105
8080

8181

82+
class DataframeDisplayConfig:
83+
"""Configuration for displaying DataFrame results.
84+
85+
This class allows you to control how DataFrames are displayed in Python.
86+
"""
87+
88+
def __init__(
89+
self,
90+
max_table_bytes: int = None,
91+
min_table_rows: int = None,
92+
max_cell_length: int = None,
93+
max_table_rows_in_repr: int = None,
94+
) -> None:
95+
"""Create a new :py:class:`DataframeDisplayConfig` instance.
96+
97+
Args:
98+
max_table_bytes: Maximum bytes to display for table presentation (default: 2MB)
99+
min_table_rows: Minimum number of table rows to display (default: 20)
100+
max_cell_length: Maximum length of a cell before it gets minimized (default: 25)
101+
max_table_rows_in_repr: Maximum number of rows to display in repr string output (default: 10)
102+
"""
103+
self.config_internal = DataframeDisplayConfigInternal(
104+
max_table_bytes=max_table_bytes,
105+
min_table_rows=min_table_rows,
106+
max_cell_length=max_cell_length,
107+
max_table_rows_in_repr=max_table_rows_in_repr,
108+
)
109+
110+
@property
111+
def max_table_bytes(self) -> int:
112+
"""Get the maximum bytes to display for table presentation."""
113+
return self.config_internal.max_table_bytes
114+
115+
@max_table_bytes.setter
116+
def max_table_bytes(self, value: int) -> None:
117+
"""Set the maximum bytes to display for table presentation."""
118+
self.config_internal.max_table_bytes = value
119+
120+
@property
121+
def min_table_rows(self) -> int:
122+
"""Get the minimum number of table rows to display."""
123+
return self.config_internal.min_table_rows
124+
125+
@min_table_rows.setter
126+
def min_table_rows(self, value: int) -> None:
127+
"""Set the minimum number of table rows to display."""
128+
self.config_internal.min_table_rows = value
129+
130+
@property
131+
def max_cell_length(self) -> int:
132+
"""Get the maximum length of a cell before it gets minimized."""
133+
return self.config_internal.max_cell_length
134+
135+
@max_cell_length.setter
136+
def max_cell_length(self, value: int) -> None:
137+
"""Set the maximum length of a cell before it gets minimized."""
138+
self.config_internal.max_cell_length = value
139+
140+
@property
141+
def max_table_rows_in_repr(self) -> int:
142+
"""Get the maximum number of rows to display in repr string output."""
143+
return self.config_internal.max_table_rows_in_repr
144+
145+
@max_table_rows_in_repr.setter
146+
def max_table_rows_in_repr(self, value: int) -> None:
147+
"""Set the maximum number of rows to display in repr string output."""
148+
self.config_internal.max_table_rows_in_repr = value
149+
150+
82151
class SessionConfig:
83152
"""Session configuration options."""
84153

src/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ impl Default for PyDataframeDisplayConfig {
127127
#[derive(Clone, Default)]
128128
pub struct PySessionConfig {
129129
pub config: SessionConfig,
130-
#[pyo3(get, set)]
131130
pub display_config: PyDataframeDisplayConfig,
132131
}
133132

0 commit comments

Comments
 (0)