-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: 1.3.0 styler.render() throws exception when using highlight_max/highlight_min (code worked with pandas 1.2.5) #42466
Comments
Do you mean this:
or do you mean this (notice no list):
which works just fine? |
Additionally it is not df = pd.DataFrame({'col_0': [0, 'a']})
numpy.nanmax(df["col_0"])
# TypeError: '>=' not supported between instances of 'int' and 'str' |
That's correct.
I tried to simplify the problem, my original was (which runs into the same error): import pandas as pd
# throws a # ValueError('The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()')
pd.DataFrame({'col_0': [pd.to_datetime('1/1/2000'), pd.to_timedelta(0, unit='d'), pd.period_range(start='2000-01-01', end='2000-01-02')]}).style.highlight_max().render() I did some research. Version 1.2.5 also uses In 1.3.0 the |
I don't believe this is a bug or your expected output is warranted. Your original code works in 1.2.5 simply because Your requests comes down to either:
I prefer the second for two reasons.
df = DataFrame([['a', 'b'], ['c', 'd']])
df.style.highlight_max().render() # pre-selects only numeric columns In 1.3.0 there is now a correct comparison made and the maximum of strings is highlighted. df.style.highlight_max().render() # highlights 'c' and 'd' I think it is more valuable for the method to work where it should, than avoid errors where it can't. |
Thank you. I understand the reasons and can live with the changed and now more consistent behavior. Because |
Fair point, was my bad, must have missed it when I made the changes. |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample
These are minimal examples which throw an exception. The same problem exist when you use
highlight_min
instead ofhighlight_max
.Problem description
All examples worked in pandas 1.2.5 without throwing an exception.
Expected Output
The code doesn't throw an exception.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f00ed8f
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-77-generic
Version : #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.0
numpy : 1.21.0
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 57.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: