Skip to content

Commit 2936455

Browse files
committed
refactor: improve comments and restructure FormatterConfig usage in PyDataFrame
1 parent 302f785 commit 2936455

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/dataframe.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl PyDataFrame {
176176
}
177177

178178
fn __repr__(&self, py: Python) -> PyDataFusionResult<String> {
179-
// Get the Python formatter and config
179+
// Get the Python formatter config
180180
let PythonFormatter {
181181
formatter: _,
182182
config,
@@ -223,15 +223,13 @@ impl PyDataFrame {
223223

224224
let py_schema = self.schema().into_pyobject(py)?;
225225

226-
// Call format_html method on the formatter
227226
let kwargs = pyo3::types::PyDict::new(py);
228227
let py_batches_list = PyList::new(py, py_batches.as_slice())?;
229228
kwargs.set_item("batches", py_batches_list)?;
230229
kwargs.set_item("schema", py_schema)?;
231230
kwargs.set_item("has_more", has_more)?;
232231
kwargs.set_item("table_uuid", table_uuid)?;
233232

234-
// Use the formatter from the struct
235233
let html_result = formatter.call_method("format_html", (), Some(&kwargs))?;
236234
let html_str: String = html_result.extract()?;
237235

@@ -859,9 +857,11 @@ async fn collect_record_batches_to_display(
859857
df: DataFrame,
860858
config: FormatterConfig,
861859
) -> Result<(Vec<RecordBatch>, bool), DataFusionError> {
862-
let max_bytes = config.max_bytes;
863-
let min_rows = config.min_rows;
864-
let max_rows = config.repr_rows;
860+
let FormatterConfig {
861+
max_bytes,
862+
min_rows,
863+
repr_rows,
864+
} = config;
865865

866866
let partitioned_stream = df.execute_stream_partitioned().await?;
867867
let mut stream = futures::stream::iter(partitioned_stream).flatten();
@@ -870,7 +870,7 @@ async fn collect_record_batches_to_display(
870870
let mut record_batches = Vec::default();
871871
let mut has_more = false;
872872

873-
while (size_estimate_so_far < max_bytes && rows_so_far < max_rows) || rows_so_far < min_rows {
873+
while (size_estimate_so_far < max_bytes && rows_so_far < repr_rows) || rows_so_far < min_rows {
874874
let mut rb = match stream.next().await {
875875
None => {
876876
break;
@@ -900,8 +900,8 @@ async fn collect_record_batches_to_display(
900900
}
901901
}
902902

903-
if rows_in_rb + rows_so_far > max_rows {
904-
rb = rb.slice(0, max_rows - rows_so_far);
903+
if rows_in_rb + rows_so_far > repr_rows {
904+
rb = rb.slice(0, repr_rows - rows_so_far);
905905
has_more = true;
906906
}
907907

0 commit comments

Comments
 (0)