Skip to content

BUG: Improve col_space in to_html to allow css length strings (#25941) #26012

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

Merged
merged 12 commits into from
Apr 29, 2019

Conversation

ArtificialQualia
Copy link
Contributor

Adds the ability to pass a string as the col_space parameter in to_html.

For backwards compatibility and similarity for other to_* functions, I kept in the ability to pass an int. The int is automatically turned into px units (I chose px because that is the default if you put a unit-less CSS length into chrome). If you want that removed and to always expect a string, let me know.

result = result.split('tbody')[0]
hdrs = [x for x in result.split("\n") if re.search(r"<th[>\s]", x)]
for h in hdrs:
assert "min-width: 100%" in h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we parametrize this for a few length units and make a stronger assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, let me know if it is enough units and a strong enough assertion for you

Copy link
Member

@simonjayhawkins simonjayhawkins Apr 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may also need a test with a multiIndex for the columns and also to_html(header=False).

@WillAyd WillAyd added the Code Style Code style, linting, code_checks label Apr 6, 2019
@codecov
Copy link

codecov bot commented Apr 6, 2019

Codecov Report

Merging #26012 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26012      +/-   ##
==========================================
- Coverage   91.82%   91.81%   -0.01%     
==========================================
  Files         175      175              
  Lines       52551    52553       +2     
==========================================
- Hits        48256    48254       -2     
- Misses       4295     4299       +4
Flag Coverage Δ
#multiple 90.38% <100%> (ø) ⬆️
#single 40.72% <16.66%> (-0.14%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/format.py 97.89% <ø> (ø) ⬆️
pandas/io/formats/html.py 99.36% <100%> (ø) ⬆️
pandas/core/frame.py 96.79% <100%> (-0.12%) ⬇️
pandas/io/gbq.py 75% <0%> (-12.5%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1fee91...36f872c. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 6, 2019

Codecov Report

Merging #26012 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26012      +/-   ##
==========================================
+ Coverage   91.84%   91.97%   +0.12%     
==========================================
  Files         175      175              
  Lines       52517    52374     -143     
==========================================
- Hits        48233    48169      -64     
+ Misses       4284     4205      -79
Flag Coverage Δ
#multiple 90.52% <100%> (+0.13%) ⬆️
#single 40.69% <25%> (-0.16%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/format.py 97.9% <ø> (+0.01%) ⬆️
pandas/io/formats/html.py 99.36% <100%> (ø) ⬆️
pandas/core/frame.py 96.9% <100%> (-0.01%) ⬇️
pandas/util/_doctools.py 0% <0%> (-12.88%) ⬇️
pandas/io/gbq.py 78.94% <0%> (-8.56%) ⬇️
pandas/core/indexing.py 90.53% <0%> (-0.35%) ⬇️
pandas/core/sparse/frame.py 95.49% <0%> (-0.21%) ⬇️
pandas/core/computation/engines.py 88.33% <0%> (-0.2%) ⬇️
pandas/util/testing.py 90.61% <0%> (-0.12%) ⬇️
pandas/tseries/holiday.py 93.1% <0%> (-0.11%) ⬇️
... and 83 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f6b90a...1bcc5c6. Read the comment docs.

@pep8speaks
Copy link

pep8speaks commented Apr 6, 2019

Hello @ArtificialQualia! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-04-28 19:40:53 UTC

@simonjayhawkins
Copy link
Member

For backwards compatibility and similarity for other to_* functions, I kept in the ability to pass an int. The int is automatically turned into px units (I chose px because that is the default if you put a unit-less CSS length into chrome). If you want that removed and to always expect a string, let me know.

it makes sense to just be px, since the parameter is applied to all columns % makes less sense.

col_space='The minimum width of each column in CSS length '
'units. An int is assumed to be px units.\n\n'
' .. versionadded:: 0.25.0\n'
' Abillity to use str')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a blank line here. does this render properly when this doc-page is built (meaning w/o warning)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't need an extra blank line, but I did need to indent the line under versionadded a little more to remove warnings. Should be all set now. Here is what it looks like rendered:

image

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc-string formatting

@@ -643,3 +643,17 @@ def test_to_html_round_column_headers():
notebook = df.to_html(notebook=True)
assert "0.55555" in html
assert "0.556" in notebook


@pytest.mark.parametrize("unit", ['100px', '10%', '5em', 150])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per @simonjayhawkins does it make sense to allow percentages here?

@ArtificialQualia
Copy link
Contributor Author

Anything more needed on this PR?

@jreback jreback added this to the 0.25.0 milestone Apr 28, 2019
"""
if header and self.fmt.col_space is not None:
if isinstance(self.fmt.col_space, int):
self.fmt.col_space = ('{colspace}px'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of actually changing this parameter, can you just use it directly; I would do this check instead in the initializer step

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to init as requested

@jreback
Copy link
Contributor

jreback commented Apr 28, 2019

lgtm. @WillAyd

@WillAyd WillAyd merged commit 9feb3ad into pandas-dev:master Apr 29, 2019
@WillAyd
Copy link
Member

WillAyd commented Apr 29, 2019

Thanks @ArtificialQualia !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_html(col_space=<int>) does not set min-width style correctly.
5 participants