Skip to content

Commit 354ff45

Browse files
committed
feat: Add display configuration options to SessionContext for DataFrame presentation
1 parent 1737973 commit 354ff45

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

python/datafusion/context.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,40 @@ def global_ctx(cls) -> SessionContext:
622622
wrapper.ctx = internal_ctx
623623
return wrapper
624624

625+
def with_display_config(
626+
self,
627+
max_table_bytes: Optional[int] = None,
628+
min_table_rows: Optional[int] = None,
629+
max_cell_length: Optional[int] = None,
630+
max_table_rows_in_repr: Optional[int] = None,
631+
) -> SessionContext:
632+
"""Configure the display options for DataFrames.
633+
634+
Args:
635+
max_table_bytes: Maximum bytes to display for table presentation
636+
(default: 2MB)
637+
min_table_rows: Minimum number of table rows to display
638+
(default: 20)
639+
max_cell_length: Maximum length of a cell before it gets minimized
640+
(default: 25)
641+
max_table_rows_in_repr: Maximum number of rows to display in repr
642+
string output (default: 10)
643+
644+
Returns:
645+
A new :py:class:`SessionContext` object with the updated display settings.
646+
"""
647+
display_config = DataframeDisplayConfig(
648+
max_table_bytes=max_table_bytes,
649+
min_table_rows=min_table_rows,
650+
max_cell_length=max_cell_length,
651+
max_table_rows_in_repr=max_table_rows_in_repr,
652+
)
653+
654+
klass = self.__class__
655+
obj = klass.__new__(klass)
656+
obj.ctx = self.ctx.with_display_config(display_config.config_internal)
657+
return obj
658+
625659
def enable_url_table(self) -> SessionContext:
626660
"""Control if local files can be queried as tables.
627661

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub struct PySessionContext {
324324

325325
#[pymethods]
326326
impl PySessionContext {
327-
#[pyo3(signature = (config=None, runtime=None))]
327+
#[pyo3(signature = (config=None, runtime=None, display_config=None))]
328328
#[new]
329329
pub fn new(
330330
config: Option<PySessionConfig>,

0 commit comments

Comments
 (0)