Comments (5)
This is not a bug. It is as documented. escaping is done before formatter
.
This is actually a feature by design and was implemented this way after careful consideration.
Achieving the result you want is possible. It is simply to design your own formatter that performs escaping after it has formatted your text. Then you do not add anything to the esacpe
argument directly.
from pandas.
This is actually a feature by design and was implemented this way after careful consideration.
Just curious - what is the benefit of escaping prior?
from pandas.
To be honest I can't remember exactly, we are going back a few years.
It may be that in the way it is designed you can achieve both, whilst that might be trickier with the reverse.
It seems more natural that if you:
- Turned on escape and added a formatter your formatter is applied to the strings that have been pre-escaped.
- Turned off escape and added a formatter that formatter will operate directly on the strings unchanged (and then can include your own escaping function if you so choose).
from pandas.
To be honest I can't remember exactly, we are going back a few years.
Makes sense, no problem. The trouble I'm having is I can't envision a use case where you wouldn't want escaping to be the very last step.
It is simply to design your own formatter that performs escaping after it has formatted your text.
What would the code for this look like? At a glance, it sounds intricate in the general case.
from pandas.
OK I think it came to me.
Setup a DF and show it (you have to escape this to see the <div>
):
df = DataFrame(["ab&%<div>"])
df.style.format(escape="html")
Since Styler is a display tool one can use the formatter to hack elements into HTML or LaTeX, for specific rows, columns or even cells, with native HTML or LaTeX commands. Something like this:
df.style.format('<span style="color:red;">{}</span>', escape="html")
This will not work if you escape after the fact. You can simulate escaping after as follows:
from pandas.io.formats.style_render import _str_escape
def custom_formatter(s):
s = '<span style="color:red;">{}</span>'.format(s)
return _str_escape(s, "html")
df.style.format(custom_formatter)
Thus with the current system you can do everything if you know the various mechanisms.
You could of course argue that one could write a customer formatter to escape first and then format, but I do also think there were possibly some other reasons when mixing the other things that the format function did, e.g. hyperlinks, which shouldn't be escaped.
from pandas.
Related Issues (20)
- BUG: Pandas Overrides Default NumPy Function's Behavior
- BUG: DatetimeIndex.is_year_start breaks on double-digit frequencies HOT 6
- BUG: DatetimeIndex.is_year_start breaks for business-day frequency where `n` is greater than 1 HOT 4
- ENH: include cache in memory_usage
- BUG: wrong item assignment by repeated key with ArrowExtensionArray
- DOC: Table Visualization Style Guide Notebook does not work HOT 1
- DOC: Enforce Numpy Docstring Validation | pandas.tseries.offsets.Week to YearEnd HOT 1
- BUG: ewm with adjust=False and ignore_na=False does not properly take NaNs into account HOT 3
- DOC: Enforce Numpy Docstring Validation | pandas.api.extensions.ExtensionArray HOT 2
- BUG: convert_dtypes() doesn't convert after a previous conversion was done HOT 7
- DOC: convert_dtypes incorrectly assumes the output is a always DataFrame
- ENH: Add totality validation to merge method HOT 1
- BUG: pandas testsuite with numpy 2.0.0rc1 fails on numexpr HOT 3
- DISC: nanoarrow-backed ArrowStringArray HOT 9
- BUG: next_workday observance wrongly adds BDay to holidays on weekdays HOT 2
- BUG: Unexpected behaviour when attempting to read Stata 104 format dta files
- BUG: RuntimeWarning: coroutine 'AsyncCursor.execute' was never awaited HOT 3
- BUG: pd.to_datetime() produces NaN when first row is a time in the current month HOT 4
- DOC: Enforce Numpy Docstring Validation | pandas.api.types HOT 1
- Default string dtype should not raise fallback performance warnings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas.