feat: dataframe string formatter#1170
Merged
timsaucer merged 4 commits intoapache:mainfrom Jun 25, 2025
Merged
Conversation
a9b9679 to
f04b973
Compare
kosiew
approved these changes
Jun 25, 2025
Contributor
kosiew
left a comment
There was a problem hiding this comment.
Looks good to me.
Left some suggestions.
python/datafusion/dataframe.py
Outdated
Comment on lines
1115
to
1127
| @staticmethod | ||
| def default_str_repr( | ||
| batches: list[pa.RecordBatch], | ||
| schema: pa.Schema, | ||
| has_more: bool, | ||
| table_uuid: str | None = None, | ||
| ) -> str: | ||
| """Return the default string representation of a DataFrame. | ||
|
|
||
| This method is used by the default formatter and implemented in Rust for | ||
| performance reasons. | ||
| """ | ||
| return DataFrameInternal.default_str_repr(batches, schema, has_more, table_uuid) |
Contributor
There was a problem hiding this comment.
default_str_repr is at the bottom of the class.
It might be clearer to place it alongside other repr/formatter methods (repr, repr_html) for cohesion.
Comment on lines
+263
to
+265
| @classmethod | ||
| def is_styles_loaded(cls) -> bool: | ||
| """Check if HTML styles have been loaded in the current session. |
Contributor
There was a problem hiding this comment.
I thought of a better idea to implement this
#1171
Member
Author
There was a problem hiding this comment.
Excellent! Maybe we open a separate PR for this?
python/datafusion/html_formatter.py
Outdated
| "The module 'html_formatter' is deprecated and will be removed in the next release." | ||
| "Please use 'dataframe_formatter' instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, |
Contributor
There was a problem hiding this comment.
Using stacklevel=2 may not point users to their import site. Consider stacklevel=3 or more, so the warning originates where they imported it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
None
Rationale for this change
We recently added a html formatter, which is useful for generating html tables as a customer. This adds the similar feature to
__repr__to allow for text based formatting.What changes are included in this PR?
Add method to formatter to format a dataframe as a string.
Renamed html_formatter to dataframe_formatter.
Are there any user-facing changes?
Yes, the
html_formattermodule has been renamed todataframe_formatter. A deprecation warning exists if any users try the old method. This was only released a couple of weeks ago so I doubt there has been time for adoption yet.