-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add option for DataFrame.to_html() to render URL data as links (#2679) #23715
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
WillAyd
merged 24 commits into
pandas-dev:master
from
benjaminarjun:feature/render-df-link-issue2679
Dec 13, 2018
Merged
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0702824
ENH: Add render_links option to DataFrame to_html()
benjaminarjun 61c22a3
Remove usage of dedent
benjaminarjun 67cfe5f
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 793006d
HTML writer to write unicode
benjaminarjun ccffd5f
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 13e20ea
Move _is_url import to correct position
benjaminarjun db31c1d
A few style fixes
benjaminarjun 13bbca4
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 61737ed
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun a59bc4f
Pass expected start and end tags as parameters
benjaminarjun b9e5aa7
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 14b79e1
Move render_links test expectations to separate files
benjaminarjun dd83afa
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 2f02e28
Add render_links description and example to whatsnew and IO docs
benjaminarjun 7ecbeb6
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 7e0de08
Minor style fix in io.rst
benjaminarjun 8683d56
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 7b5b323
Style fix on render_links test
benjaminarjun 505a2f0
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 05f17f2
Add versionadded in io.rst
benjaminarjun bb637a8
boolean -> bool and newlines for render_links_*.html
benjaminarjun c01306d
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun 78ed4b9
Add link to IO docs from render_links whatsnew entry
benjaminarjun 9f3e058
Merge branch 'master' into feature/render-df-link-issue2679_test
benjaminarjun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>foo</th> | ||
<th>bar</th> | ||
<th>None</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>0</td> | ||
<td>http://pandas.pydata.org/?q1=a&q2=b</td> | ||
<td>pydata.org</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>0</td> | ||
<td>www.pydata.org</td> | ||
<td>pydata.org</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a linefeed here (and on the one below) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>foo</th> | ||
<th>bar</th> | ||
<th>None</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>0</td> | ||
<td><a href="http://pandas.pydata.org/?q1=a&q2=b" target="_blank">http://pandas.pydata.org/?q1=a&q2=b</a></td> | ||
<td>pydata.org</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>0</td> | ||
<td>www.pydata.org</td> | ||
<td>pydata.org</td> | ||
</tr> | ||
</tbody> | ||
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,3 +477,28 @@ def test_to_html_float_format_no_fixed_width(self, datapath): | |
df = DataFrame({'x': [100.0]}) | ||
expected = expected_html(datapath, 'gh22270_expected_output') | ||
assert df.to_html(float_format='%.0f') == expected | ||
|
||
@pytest.mark.parametrize("render_links, file_name", [ | ||
(True, 'render_links_true'), | ||
(False, 'render_links_false'), | ||
]) | ||
def test_to_html_render_links(self, render_links, file_name, datapath): | ||
# GH 2679 | ||
data = [ | ||
{ | ||
'foo': 0, | ||
'bar': 'http://pandas.pydata.org/?q1=a&q2=b', | ||
None: 'pydata.org', | ||
}, | ||
{ | ||
'foo': 0, | ||
'bar': 'www.pydata.org', | ||
None: 'pydata.org', | ||
}, | ||
] | ||
df = DataFrame(data, columns=['foo', 'bar', None], | ||
benjaminarjun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
index=range(len(data))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to pass |
||
|
||
result = df.to_html(render_links=render_links) | ||
expected = expected_html(datapath, file_name) | ||
assert result == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 our standard is for bool, @datapythonista should probably validate this generally as I seem mixed usage all over the place.
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.
yes, we still need to fix many cases before we can validate this, but if you run
./scripts/validate_docstrings.py pandas.DataFrame.to_html
it will report this, and any other formatting issue.