Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: overriden methods of subclasses of Styler are not called during rendering #52728

Closed
2 of 3 tasks
hottwaj opened this issue Apr 18, 2023 · 4 comments · Fixed by #52919
Closed
2 of 3 tasks

BUG: overriden methods of subclasses of Styler are not called during rendering #52728

hottwaj opened this issue Apr 18, 2023 · 4 comments · Fixed by #52919
Assignees
Labels
Bug good first issue Styler conditional formatting using DataFrame.style

Comments

@hottwaj
Copy link

hottwaj commented Apr 18, 2023

Pandas version checks

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

  • 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 : 478d340
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

@hottwaj hottwaj added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 18, 2023
@attack68
Copy link
Contributor

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.

@attack68 attack68 added Styler conditional formatting using DataFrame.style good first issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 18, 2023
@nicklausroach
Copy link
Contributor

take

YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
@anshuman0123
Copy link

please give me this issue to solve

YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
@attack68
Copy link
Contributor

@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.

YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
YifanChao added a commit to YifanChao/pandas that referenced this issue Apr 23, 2023
…rendering pandas-dev#52728

BUG: overriden methods of subclasses of Styler are not called during rendering pandas-dev#52728
mroeschke pushed a commit that referenced this issue Apr 27, 2023
…rendering #52728 (#52919)

* use type() instead of __class__

* add test

* remove unnecessary file

* typo

* revert change to class method

---------

Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro.home>
Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro-2.local>
topper-123 pushed a commit to topper-123/pandas that referenced this issue May 7, 2023
…rendering pandas-dev#52728 (pandas-dev#52919)

* use type() instead of __class__

* add test

* remove unnecessary file

* typo

* revert change to class method

---------

Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro.home>
Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro-2.local>
Rylie-W pushed a commit to Rylie-W/pandas that referenced this issue May 19, 2023
…rendering pandas-dev#52728 (pandas-dev#52919)

* use type() instead of __class__

* add test

* remove unnecessary file

* typo

* revert change to class method

---------

Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro.home>
Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro-2.local>
Daquisu pushed a commit to Daquisu/pandas that referenced this issue Jul 8, 2023
…rendering pandas-dev#52728 (pandas-dev#52919)

* use type() instead of __class__

* add test

* remove unnecessary file

* typo

* revert change to class method

---------

Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro.home>
Co-authored-by: Nicklaus Roach <nicklausroach@MacBook-Pro-2.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug good first issue Styler conditional formatting using DataFrame.style
Projects
None yet
4 participants