Skip to content

Commit 03921d9

Browse files
authored
feat: dataframe string formatter (#1170)
* Add string formatter * Rename html_formatter to dataframe_formatter * Add deprecation warning * Small adjustments based on user feedback
1 parent ef62fa8 commit 03921d9

File tree

6 files changed

+829
-740
lines changed

6 files changed

+829
-740
lines changed

python/datafusion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
SQLOptions,
4747
)
4848
from .dataframe import DataFrame, ParquetColumnOptions, ParquetWriterOptions
49+
from .dataframe_formatter import configure_formatter
4950
from .expr import (
5051
Expr,
5152
WindowFrame,
5253
)
53-
from .html_formatter import configure_formatter
5454
from .io import read_avro, read_csv, read_json, read_parquet
5555
from .plan import ExecutionPlan, LogicalPlan
5656
from .record_batch import RecordBatch, RecordBatchStream

python/datafusion/dataframe.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import polars as pl
5353
import pyarrow as pa
5454

55-
from datafusion._internal import DataFrame as DataFrameInternal
5655
from datafusion._internal import expr as expr_internal
5756

5857
from enum import Enum
@@ -327,6 +326,20 @@ def __repr__(self) -> str:
327326
def _repr_html_(self) -> str:
328327
return self.df._repr_html_()
329328

329+
@staticmethod
330+
def default_str_repr(
331+
batches: list[pa.RecordBatch],
332+
schema: pa.Schema,
333+
has_more: bool,
334+
table_uuid: str | None = None,
335+
) -> str:
336+
"""Return the default string representation of a DataFrame.
337+
338+
This method is used by the default formatter and implemented in Rust for
339+
performance reasons.
340+
"""
341+
return DataFrameInternal.default_str_repr(batches, schema, has_more, table_uuid)
342+
330343
def describe(self) -> DataFrame:
331344
"""Return the statistics for this DataFrame.
332345

0 commit comments

Comments
 (0)