Skip to content

REF: pandas/io/formats/format.py #36407

Closed
@ivanovmg

Description

@ivanovmg

Is your feature request related to a problem?

class DataFrameFormatter seems mostly to target console formatting, while it plays a role of the mediator for to_latex and to_html conversions.
It is noticeable, that some kwargs, like table_id, render_links are pertaining to html only. Meanwhile dataframe truncation (present in init) is not applicable to latex formatting.
Probably needs refactoring.

Describe the solution you'd like

I suggest creating TableFormatterAbstract class.
Inherit from it: ConsoleFormatter, HTMLFormatter and LatexFormatter.
Put all the required input parameters into the corresponding init of each class (would not need to provide unnecessary kwargs).
Generic functionality like dataframe truncation can be shared via a mixin class TruncateMixin.
Drop DataFrameFormatter and instead of it call proper XFormatter where required.

API breaking implications

Should not affect public API, as will deal only with the internal implementation.

Describe alternatives you've considered

Separate ConsoleFormatter, similarly to HTMLFormatter and LatexFormatter and call it from DataFrameFormatter.to_string method.
This, however will leave DataFrameFormatter with only three public methods to_string, to_html and to_latex.
The problem here is that we still carry unnecessary kwargs, which are not applicable to a particular formatting.

Additional context

I would be interested to work on this. Would the team be interested in such refactoring?

Metadata

Metadata

Assignees

Labels

Output-Formatting__repr__ of pandas objects, to_stringRefactorInternal refactoring of code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions