[x] A description of the changes is added to the description of this PR.
[ ] If there is a related issue, make sure it is linked to this PR.
[x] If you've fixed a bug or added code that should be tested, add tests!
[x] If you've added or modified a feature, documentation in docs is updated
Description of changes
This PR proposes to deprecate the existing methods of configuring the output format of chispa through the use of the DefaultFormats and arbitrary dataclasses. Currently there are a few issues with this approach;
Poor error handling; what if a color does not exist?
How does a user know which colors are available?
Colors and formatting styles (e.g. bold) are all mixed together
A user can specify multiple colors without that raising an error,
Difficult to add proper static typing in the future
A user needs to provide all keys in his custom formats dataclass, even if they want to keep most the same to the defaults.
How do a user know which keys their custom dataclass should have?
As an alternative, this PR proposes to replace it with the classes Color, Style, Format, and FormattingConfig, so it can be used as
Enhanced error handling and validation of color and style inputs.
Notes
Even though we do not actively use type hints yet, this PR introduces them for the new classes. In the future we probably want to add type hints to the entire project and enable mypy. This PR also adds the line from __future__ import annotations to all files through the use of ruff, to provide type hinting compatiblity in Python 3.8 and 3.9
PR Checklist
docs
is updatedDescription of changes
This PR proposes to deprecate the existing methods of configuring the output format of
chispa
through the use of theDefaultFormats
and arbitrary dataclasses. Currently there are a few issues with this approach;As an alternative, this PR proposes to replace it with the classes
Color
,Style
,Format
, andFormattingConfig
, so it can be used asor
or similarly:
This brings:
Notes
mypy
. This PR also adds the linefrom __future__ import annotations
to all files through the use of ruff, to provide type hinting compatiblity in Python 3.8 and 3.9test_deprectaed.py
.assert_basic_rows_equality(df1.collect(), df2.collect(), formats=CustomFormats())
will displayassert_basic_rows_equality(df1.collect(), df2.collect(), formats=DefaultFormats())
will display