Skip to content

ENH: Make ExcelFormatter.header_style a class attribute instead of a property #50336

Closed
@terazus

Description

@terazus

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When I'm trying to remove the default ExcelFormatter header style, my IDE complains that the property cannot be set.
Pycharm suggest adding a setter but I don't think it's the correct behaviour.
image

This is very minor improvement as code runs perfectly well.

Feature Description

Change the ExcelFormatter header_style to be a class attribute instead of a property:

class ExcelFormatter:
    """
    Class for formatting a DataFrame to a list of ExcelCells,

    Parameters
    ----------
    ...
    """

    max_rows = 2 ** 20
    max_cols = 2 ** 14
    header_style: dict[str, dict[str, str | bool]] = {
        "font": {"bold": True},
        "borders": {
            "top": "thin",
            "right": "thin",
            "bottom": "thin",
            "left": "thin",
        },
        "alignment": {"horizontal": "center", "vertical": "top"},
    }

    def __init__(
            self,
            df,
            na_rep: str = "",
            float_format: str | None = None,
            cols: Sequence[Hashable] | None = None,
            header: Sequence[Hashable] | bool = True,
            index: bool = True,
            index_label: IndexLabel | None = None,
            merge_cells: bool = False,
            inf_rep: str = "inf",
            style_converter: Callable | None = None,
    ) -> None:...

Alternative Solutions

Pycharm setter suggestion (which i find less relevant):

class ExcelFormatter:
    """
    Class for formatting a DataFrame to a list of ExcelCells,

    Parameters
    ----------
    ...
    """

    max_rows = 2 ** 20
    max_cols = 2 ** 14

    def __init__(
            self,
            df,
            na_rep: str = "",
            float_format: str | None = None,
            cols: Sequence[Hashable] | None = None,
            header: Sequence[Hashable] | bool = True,
            index: bool = True,
            index_label: IndexLabel | None = None,
            merge_cells: bool = False,
            inf_rep: str = "inf",
            style_converter: Callable | None = None,
    ) -> None:...

    @property
    def header_style(self) -> dict[str, dict[str, str | bool]]:
        return {
            "font": {"bold": True},
            "borders": {
                "top": "thin",
                "right": "thin",
                "bottom": "thin",
                "left": "thin",
            },
            "alignment": {"horizontal": "center", "vertical": "top"},
        }

    @header_style.setter
    def header_style(self, value):
        self._header_style = value

Additional Context

Just thanks for your hard work. 🐼

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions