Skip to content
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

Add option for DataFrame.to_html() to render URL data as links (#2679) #23715

Merged

Conversation

benjaminarjun
Copy link
Contributor

@benjaminarjun benjaminarjun commented Nov 15, 2018

Two lines were added to tests that exceed the 79 character limit.

@pep8speaks
Copy link

pep8speaks commented Nov 15, 2018

Hello @benarthur91! Thanks for updating the PR.

Comment last updated on November 26, 2018 at 05:41 Hours UTC

pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/config_init.py Outdated Show resolved Hide resolved
pandas/io/formats/html.py Outdated Show resolved Hide resolved
pandas/io/formats/html.py Outdated Show resolved Hide resolved
pandas/tests/io/formats/test_to_html.py Outdated Show resolved Hide resolved
@gfyoung gfyoung added Enhancement IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Nov 15, 2018
pandas/core/frame.py Show resolved Hide resolved
@gfyoung
Copy link
Member

gfyoung commented Nov 26, 2018

@benarthur91 : This is looking good! Next up: could you resolve the merge conflicts?

@benjaminarjun
Copy link
Contributor Author

benjaminarjun commented Nov 26, 2018

Thanks for the feedback everyone, I've pushed the requested changes. I'm unfamiliar with the PR workflow, so please let me know if I've done anything incorrectly.

Edit: Thanks @gfyoung, I'm assuming this means rebase onto master, resolve conflicts, and force push that branch over the current?

@gfyoung
Copy link
Member

gfyoung commented Nov 26, 2018

I'm assuming this means rebase onto master, resolve conflicts, and force push that branch over the current?

Yep, that's correct.

@WillAyd
Copy link
Member

WillAyd commented Nov 26, 2018

Typically preferred if you merge in the latest master instead of rebasing. Keeps github comment history and doesn’t require a force push

@benjaminarjun
Copy link
Contributor Author

Gotcha, sorry about that. I still have the pre-rebase branch with original commits, would it be helpful if I pushed that one up instead?

@gfyoung
Copy link
Member

gfyoung commented Nov 26, 2018

Gotcha, sorry about that. I still have the pre-rebase branch with original commits, would it be helpful if I pushed that one up instead?

@benarthur91 : Just leave it as is and work off what you just pushed. It's fine.

@benjaminarjun
Copy link
Contributor Author

Does anyone know what might have happened? Getting a seemingly unrelated error in pandas/tests/plotting/test_datetimelike.py, I couldn't see any obvious reason that would have happened.

@gfyoung
Copy link
Member

gfyoung commented Nov 29, 2018

Might be a weird Travis thing. Don't forget to fix the isort error on the other Travis build though.

@benjaminarjun
Copy link
Contributor Author

Ah, I didn't see a clear error message and assumed it was related to the other failure. As you mention isort, I'm now thinking it's either a) imports are in the wrong order or b) it doesn't like that I'm importing a private method?

Where can I look to find the proper order of imports? Also I ran flake8 on frame.py locally and it reported no issues (even when I changed the order of imports), would you expect it to?

@gfyoung
Copy link
Member

gfyoung commented Nov 29, 2018

@benarthur91 : You need to install isort via pip and run the command itself (isort )

@benjaminarjun
Copy link
Contributor Author

Pretty neat :) Thanks for clarifying, I just pushed that change.

@codecov
Copy link

codecov bot commented Nov 29, 2018

Codecov Report

Merging #23715 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23715      +/-   ##
==========================================
+ Coverage   92.22%   92.22%   +<.01%     
==========================================
  Files         162      162              
  Lines       51777    51785       +8     
==========================================
+ Hits        47751    47759       +8     
  Misses       4026     4026
Flag Coverage Δ
#multiple 90.62% <100%> (ø) ⬆️
#single 43.01% <11.11%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/frame.py 96.91% <ø> (ø) ⬆️
pandas/io/formats/format.py 97.98% <100%> (ø) ⬆️
pandas/io/formats/html.py 98.64% <100%> (+0.03%) ⬆️

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 b7ee829...9f3e058. Read the comment docs.

@benjaminarjun
Copy link
Contributor Author

Is there anything else I should do to clean this up right now?

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Minor comments otherwise lgtm

pandas/tests/io/formats/test_to_html.py Outdated Show resolved Hide resolved
pandas/io/formats/html.py Outdated Show resolved Hide resolved
pandas/io/formats/html.py Outdated Show resolved Hide resolved
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.

can you add a whatsnew note, New Features is prob good. Also we have some docs on writing .to_html() in io.rst, can you add an example of this there (with a versionadded tag)

@benjaminarjun
Copy link
Contributor Author

Added note to whatsnew and also a short description and example in io.rst

I also checked the last two boxes in the original (autogenerated) comment - I'm assuming that's for me to do and not someone else, but not sure. Let me know if there's anything else I can do.

},
]
df = DataFrame(data, columns=['foo', 'bar', None],
index=range(len(data)))
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to pass index here as this is the default behavior

doc/source/io.rst Show resolved Hide resolved
doc/source/io.rst Show resolved Hide resolved
.. ipython:: python
:suppress:

write_html(url_df, 'render_links', render_links=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this for?

Copy link
Contributor Author

@benjaminarjun benjaminarjun Dec 9, 2018

Choose a reason for hiding this comment

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

This runs the write_html() call without including its input or output in the notebook cells that appear in the doc. This makes available the static file rendered on line 2625.

I copied a pattern used elsewhere in this file, example "bold_rows" section, starting line 2584.

Copy link
Member

Choose a reason for hiding this comment

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

What's the downside of just printing it? I think creating files like this is hard to keep track of within our codebase so less than ideal

Copy link
Contributor Author

@benjaminarjun benjaminarjun Dec 11, 2018

Choose a reason for hiding this comment

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

The generated HTML is also printed in a notebook cell. The lines pointed out by @jreback write that HTML to a separate file that can be rendered.

Here's what it looks like after building:

image

That said, if having the rendered sample is not worth the overhead of the extra file, I'm happy to remove.

Copy link
Contributor

@jreback jreback Dec 12, 2018

Choose a reason for hiding this comment

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

hmm i am not sure we actually need to show the html, showing the rendered version is enough. but since we are doing it for all of these, ok

@jreback jreback added this to the 0.24.0 milestone Dec 12, 2018
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.

just some small comments. ping on green.

@@ -2067,6 +2067,12 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
A css id is included in the opening `<table>` tag if specified.

.. versionadded:: 0.23.0

render_links : boolean, default False
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 our standard is for bool, @datapythonista should probably validate this generally as I seem mixed usage all over the place.

Copy link
Member

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.

<td>pydata.org</td>
</tr>
</tbody>
</table>
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a linefeed here (and on the one below)

@@ -27,6 +27,7 @@ New features
- :meth:`DataFrame.corr` and :meth:`Series.corr` now accept a callable for generic calculation methods of correlation, e.g. histogram intersection (:issue:`22684`)
- :func:`DataFrame.to_string` now accepts ``decimal`` as an argument, allowing the user to specify which decimal separator should be used in the output. (:issue:`23614`)
- :func:`DataFrame.read_feather` now accepts ``columns`` as an argument, allowing the user to specify which columns should be read. (:issue:`24025`)
- :func:`DataFrame.to_html` now accepts ``render_links`` as an argument, allowing the user to generate HTML with links to any URLs that appear in the DataFrame. (:issue:`2679`)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a ref to the new docs that you added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need a link here or just a mention of the addition to docs?

Copy link
Member

Choose a reason for hiding this comment

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

If you add a link I can approve and merge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback @WillAyd Link added and all green.

@jreback
Copy link
Contributor

jreback commented Dec 13, 2018

minor point, pls ping on green. @WillAyd over to you.

@benjaminarjun
Copy link
Contributor Author

Just got in front of keyboard and was about to ping you 😃 thanks for approving, will wait to hear from @WillAyd.

@WillAyd WillAyd merged commit 2f6d682 into pandas-dev:master Dec 13, 2018
@WillAyd
Copy link
Member

WillAyd commented Dec 13, 2018

Thanks @benarthur91 - nice change!

@benjaminarjun
Copy link
Contributor Author

Thanks to everyone for all the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvement: DataFrame.to_html() to create hyperlinks
6 participants