Skip to content

Commit d30c641

Browse files
committed
refactor: Enhance DataframeDisplayConfig initialization with value validation
- Added validation for max_table_bytes, min_table_rows, max_cell_length, and max_table_rows_in_repr to ensure positive values during initialization. - Removed the deprecated with_dataframe_display_config method to streamline the configuration process.
1 parent efc041c commit d30c641

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

python/datafusion/context.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def __init__(
104104
max_table_rows_in_repr: Maximum number of rows to display in repr
105105
string output (default: 10)
106106
"""
107+
# Validate values if they are not None
108+
if max_table_bytes is not None:
109+
self._validate_positive(max_table_bytes, "max_table_bytes")
110+
if min_table_rows is not None:
111+
self._validate_positive(min_table_rows, "min_table_rows")
112+
if max_cell_length is not None:
113+
self._validate_positive(max_cell_length, "max_cell_length")
114+
if max_table_rows_in_repr is not None:
115+
self._validate_positive(max_table_rows_in_repr, "max_table_rows_in_repr")
107116
self.config_internal = DataframeDisplayConfigInternal(
108117
max_table_bytes=max_table_bytes,
109118
min_table_rows=min_table_rows,
@@ -180,46 +189,6 @@ def __init__(self, config_options: dict[str, str] | None = None) -> None:
180189
"""
181190
self.config_internal = SessionConfigInternal(config_options)
182191

183-
def with_dataframe_display_config(
184-
self,
185-
max_table_bytes: Optional[int] = None,
186-
min_table_rows: Optional[int] = None,
187-
max_cell_length: Optional[int] = None,
188-
max_table_rows_in_repr: Optional[int] = None,
189-
) -> SessionConfig:
190-
"""Configure the display options for DataFrames.
191-
192-
Args:
193-
max_table_bytes: Maximum bytes to display for table presentation
194-
(default: 2MB)
195-
min_table_rows: Minimum number of table rows to display (default: 20)
196-
max_cell_length: Maximum length of a cell before it gets minimized
197-
(default: 25)
198-
max_table_rows_in_repr: Maximum number of rows to display in repr string
199-
output (default: 10)
200-
201-
Returns:
202-
A new :py:class:`SessionConfig` object with the updated display settings.
203-
"""
204-
display_config = DataframeDisplayConfigInternal(
205-
max_table_bytes=max_table_bytes,
206-
min_table_rows=min_table_rows,
207-
max_cell_length=max_cell_length,
208-
max_table_rows_in_repr=max_table_rows_in_repr,
209-
)
210-
211-
display_config = DataframeDisplayConfigInternal(
212-
max_table_bytes=max_table_bytes,
213-
min_table_rows=min_table_rows,
214-
max_cell_length=max_cell_length,
215-
max_table_rows_in_repr=max_table_rows_in_repr,
216-
)
217-
218-
self.config_internal = self.config_internal.with_dataframe_display_config(
219-
display_config
220-
)
221-
return self
222-
223192
def with_create_default_catalog_and_schema(
224193
self, enabled: bool = True
225194
) -> SessionConfig:

0 commit comments

Comments
 (0)