Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [ ] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas
from pandas.io.formats.style import Styler

class CustomStyler(Styler):
    def _translate(self, *args, **kwargs):  # override internal _translate method
        result = super()._translate(*args, **kwargs)
        raise NotImplementedError('TODO')

data = pandas.DataFrame({'column A': [4,3,7]})
CustomStyler(data).to_html()  # CustomStyler._translate never gets called

type(CustomStyler(data)._copy())  # returns Styler not CustomStyler

Issue Description

rendering behaviour of Styler can't be customised by users, because internally Styler.render methods use ._copy to get a copy of the Styler that some internal changes are then applied to

This could be worked around by turning ._copy into a classmethod e.g. Styler._copy(cls, self) which returns a copy with the same type as self

Expected Behavior

type(CustomStyler(data)._copy()) == CustomStyler

Installed Versions

INSTALLED VERSIONS ------------------ commit : 478d340667831908b5b4bf09a2787a11a14560c9 python : 3.8.10.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-69-generic Version : #76~20.04.1-Ubuntu SMP Mon Mar 20 15:54:19 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8 pandas : 2.0.0 numpy : 1.22.0 pytz : 2021.3 dateutil : 2.8.2 setuptools : 56.0.0 pip : 21.1.1 Cython : None pytest : 6.2.5 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.0.2 lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.3 IPython : 7.31.0 pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : 2.0.1 zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None

Comment From: attack68

Thanks for the report. I can't remember the reason for the copy being added, but I do remember there being a reason. I agree that returning a copy of the subclassed type is sensible.

PRs welcome.

Comment From: nicklausroach

take

Comment From: anshuman0123

please give me this issue to solve

Comment From: attack68

@anshuman0123, @nicklausroach has already written "take" and the issue was automatically assigned to him. Please be aware of the community and be respectful towards that system.

If Nicklaus doesn't follow up or drops the issue he can always unassign himself from this task.