-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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 |
it makes sense to just be px, since the parameter is applied to all columns % makes less sense. |
pandas/core/frame.py
Outdated
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') |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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]) |
There was a problem hiding this comment.
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?
Anything more needed on this PR? |
pandas/io/formats/html.py
Outdated
""" | ||
if header and self.fmt.col_space is not None: | ||
if isinstance(self.fmt.col_space, int): | ||
self.fmt.col_space = ('{colspace}px' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
lgtm. @WillAyd |
Thanks @ArtificialQualia ! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Adds the ability to pass a string as the
col_space
parameter into_html
.For backwards compatibility and similarity for other
to_*
functions, I kept in the ability to pass anint
. Theint
is automatically turned intopx
units (I chosepx
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.