Skip to content

Commit efc041c

Browse files
committed
refactor: Extract validation logic into a separate method in DataframeDisplayConfig
- Added a private method `_validate_positive` to encapsulate the logic for validating positive integer values. - Updated setters for `max_table_bytes`, `min_table_rows`, `max_cell_length`, and `max_table_rows_in_repr` to use the new validation method, improving code readability and maintainability.
1 parent a5e16a3 commit efc041c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

python/datafusion/context.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ def __init__(
111111
max_table_rows_in_repr=max_table_rows_in_repr,
112112
)
113113

114+
def _validate_positive(self, value: int, name: str) -> None:
115+
"""Validate that the given value is positive.
116+
117+
Args:
118+
value: The value to validate
119+
name: The name of the parameter for the error message
120+
121+
Raises:
122+
ValueError: If the value is not positive
123+
"""
124+
if value <= 0:
125+
raise ValueError(f"{name} must be greater than 0")
126+
114127
@property
115128
def max_table_bytes(self) -> int:
116129
"""Get the maximum bytes to display for table presentation."""
@@ -119,8 +132,7 @@ def max_table_bytes(self) -> int:
119132
@max_table_bytes.setter
120133
def max_table_bytes(self, value: int) -> None:
121134
"""Set the maximum bytes to display for table presentation."""
122-
if value <= 0:
123-
raise ValueError("max_table_bytes must be greater than 0")
135+
self._validate_positive(value, "max_table_bytes")
124136
self.config_internal.max_table_bytes = value
125137

126138
@property
@@ -131,8 +143,7 @@ def min_table_rows(self) -> int:
131143
@min_table_rows.setter
132144
def min_table_rows(self, value: int) -> None:
133145
"""Set the minimum number of table rows to display."""
134-
if value <= 0:
135-
raise ValueError("min_table_rows must be greater than 0")
146+
self._validate_positive(value, "min_table_rows")
136147
self.config_internal.min_table_rows = value
137148

138149
@property
@@ -143,8 +154,7 @@ def max_cell_length(self) -> int:
143154
@max_cell_length.setter
144155
def max_cell_length(self, value: int) -> None:
145156
"""Set the maximum length of a cell before it gets minimized."""
146-
if value <= 0:
147-
raise ValueError("max_cell_length must be greater than 0")
157+
self._validate_positive(value, "max_cell_length")
148158
self.config_internal.max_cell_length = value
149159

150160
@property
@@ -155,8 +165,7 @@ def max_table_rows_in_repr(self) -> int:
155165
@max_table_rows_in_repr.setter
156166
def max_table_rows_in_repr(self, value: int) -> None:
157167
"""Set the maximum number of rows to display in repr string output."""
158-
if value <= 0:
159-
raise ValueError("max_table_rows_in_repr must be greater than 0")
168+
self._validate_positive(value, "max_table_rows_in_repr")
160169
self.config_internal.max_table_rows_in_repr = value
161170

162171

0 commit comments

Comments
 (0)