Skip to content

BUG: formatters ignored in to_html #36525

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

Closed
2 of 3 tasks
mizuy opened this issue Sep 21, 2020 · 2 comments · Fixed by #37958
Closed
2 of 3 tasks

BUG: formatters ignored in to_html #36525

mizuy opened this issue Sep 21, 2020 · 2 comments · Fixed by #37958
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@mizuy
Copy link

mizuy commented Sep 21, 2020

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


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

df = pd.DataFrame(dict(c1=pd.Series(range(3),dtype='int64'),
                       c2=pd.Series(range(3),dtype='Int64'),
                       c3=pd.Series(range(3),dtype='float64'),
                       c4=pd.Series(range(3),dtype='string'),
                       c5=pd.Series([0,1,0],dtype='bool'),
                       c6=pd.Series([0,1,0],dtype='boolean'),
                      ))

formatter = {c:lambda x: f"[{x}]" for c in df.columns}
display(HTML(df.to_html(formatters=formatter)))
  c1 c2 c3 c4 c5 c6
_ [0] 0 [0.0] 0 [False] False
_ [1] 1 [1.0] 1 [True] True
_ [2] 2 [2.0] 2 [False] False

Problem description

DataFrame.to_html(formatters=formatters) is not working for MaskedArrays (new arrays with missing values)

Expected Output

formatters should also be applied to MaskedArrays.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2a7d332
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.76-linuxkit
Version : #1 SMP Tue May 26 11:42:35 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20200917
Cython : 0.29.21
pytest : 6.0.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.4
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fsspec : 0.8.2
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : 0.2.2
scipy : 1.5.2
sqlalchemy : 1.3.19
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.1
xlrd : 1.2.0
xlwt : None
numba : 0.48.0

@mizuy mizuy added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 21, 2020
@khintze1
Copy link

take

@khintze1 khintze1 removed their assignment Sep 21, 2020
@ivanovmg
Copy link
Member

I confirm the issue on master branch.

Here is the thing.
In pandas.io.formats.format.format_values there is a selection of the formatter.
For Int64 type there is ExtensionArrayFormatter that gets selected, not IntArrayFormatter. Looks like the problem is in the function is_extension_array_dtype.
However, even if IntArrayFormatter is selected for Int64 inside format_values, the problem for string and boolean still persists.

@mizuy, can you please change the title to something more meaningful?

@jreback jreback added this to the 1.2 milestone Nov 20, 2020
@jreback jreback added IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 20, 2020
@jreback jreback changed the title BUG: BUG: formatters ingnored in to_html Nov 21, 2020
@jreback jreback changed the title BUG: formatters ingnored in to_html BUG: formatters ignored in to_html Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants