Skip to content

ENH: exclude html table border w/False value #45943

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 21 commits into from
Apr 17, 2022

Conversation

z3c0
Copy link
Contributor

@z3c0 z3c0 commented Feb 11, 2022

Per the HTML5 spec, border attributes on table elements are obsolete.
Borders should be implemented via CSS instead.
https://html.spec.whatwg.org/multipage/obsolete.html#attr-table-border
This enhancement will retain the default behavior of the border keyword of to_html,
but will exclude the attribute entirely upon receiving a falsy value.

closes #22692

z3c0 added 2 commits February 11, 2022 15:31
Per the HTML5 spec, border attributes on table elements are obsolete.
Borders should be implemented via CSS instead.
https://html.spec.whatwg.org/multipage/obsolete.html#attr-table-border
This enhancement will retain the default behavior of the border keyword of to_html,
but will exclude the attribute entirely upon receiving a falsy value.
Per the HTML5 spec, border attributes on table elements are obsolete.
Borders should be implemented via CSS instead.
https://html.spec.whatwg.org/multipage/obsolete.html#attr-table-border
This enhancement will retain the default behavior of the border keyword of to_html,
but will exclude the attribute entirely upon receiving a falsy value.
@z3c0
Copy link
Contributor Author

z3c0 commented Feb 11, 2022

@github-actions pre-commit

@z3c0
Copy link
Contributor Author

z3c0 commented Feb 11, 2022

Excluding the border attribute upon border=0 failed this test case: pandas\tests\io\formats\test_to_html.test_to_html_border

So I have revised the enhancement to only exclude the border attribute when border=False

**fixed typo

@z3c0 z3c0 changed the title ENH: exclude html table border w/falsy value ENH: exclude html table border w/False value Feb 11, 2022
@attack68
Copy link
Contributor

This is one of the reasons I am trying to push styler.to_html as the architecture for Dataframe.to_html.

Dataframe.to_html() produces other officially deprecated HTML: #39951

Whilst this commit solves this problem, it shouldn't be the long term solution, and its only a half measure since it still allows the old behaviour.

@jreback jreback added the IO HTML read_html, to_html, Styler.apply, Styler.applymap label Feb 27, 2022
@jreback
Copy link
Contributor

jreback commented Feb 27, 2022

can you move the whatsnew note to the I/O section

@z3c0
Copy link
Contributor Author

z3c0 commented Feb 27, 2022

@jreback done

@z3c0
Copy link
Contributor Author

z3c0 commented Mar 3, 2022

This test has failed twice for reasons that I'm unclear on

Code Checks / ASV Benchmarks

[ 50.00%] ··· ...a.TimedeltaProperties.time_timedelta_seconds           3.80±0μs
Error: Process completed with exit code 1.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Apr 8, 2022
@jreback
Copy link
Contributor

jreback commented Apr 9, 2022

pls merge master

@z3c0
Copy link
Contributor Author

z3c0 commented Apr 10, 2022

@jreback done

border = cast(int, get_option("display.html.border"))
elif not border and isinstance(border, bool):
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this instance check needed?

Copy link
Contributor Author

@z3c0 z3c0 Apr 10, 2022

Choose a reason for hiding this comment

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

Not my first choice, but it's to pass this test case:

(None, lambda df: df.to_html(border=0), "0"),

Setting border=0 has to result in border="0" being present in the output HTML. The instance check is to ensure that only a boolean can be used to hide the border.

Copy link
Contributor

Choose a reason for hiding this comment

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

why is border=0 not de-facto the same as border=False?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, it should be. That's how I originally wrote the fix. My only reason for taking this approach is to conform to the test case, which explicitly tests for a border attribute to be present upon border=0.

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 ok to treat these cases as the same and can simplify the code a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me - I will revert to my original fix, and update that test case instead

@jreback jreback added this to the 1.5 milestone Apr 10, 2022
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.

looks fine but tests are failing. ping on green

@jreback jreback merged commit 57885c6 into pandas-dev:main Apr 17, 2022
@jreback
Copy link
Contributor

jreback commented Apr 17, 2022

thanks @z3c0

@z3c0 z3c0 deleted the borderless-html-tables branch April 17, 2022 17:24
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas.DataFrame.to_html() without table border and tr style
3 participants