BUG: highlight_min and highlight_max do not work with pd.NA #42750
Labels
Bug
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Regression
Functionality that used to work in a prior pandas version
Styler
conditional formatting using DataFrame.style
Milestone
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, a copy-pastable example
Problem description
df_ok.style.highlight_min()
works correctly whiledf_bug.style.highlight_min()
returns the following error:Fix
For
highlight_min
, the error comes from https://github.com/pandas-dev/pandas/blob/v1.3.1/pandas/io/formats/style.py#L2367. Specifically, from the following line:I'm assuming this could be fixed by replacing it with:
or by making sure
to_numpy
convertspd.NA
tonp.nan
?Happy to implement a fix.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : c7f7443
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 20.4.0
Version : Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_GB.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.1
numpy : 1.19.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 52.0.0.post20210125
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : 4.9.3
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 : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: