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