Skip to content

EHN: to_{html, string} col_space col specific #32903

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
Jun 18, 2020

Conversation

quangngd
Copy link
Contributor

@quangngd quangngd commented Mar 22, 2020

In to_html, to_latex and to_string, col_space arg now accepts a list or dict where we can mention the column name to change only a specific column's width.
Haven't add test for to_latex and to_string since they too don't have test for the old col_space and I cannot think of anything less cumbersome than to count added whitespace.

@quangngd quangngd closed this Mar 22, 2020
@quangngd quangngd reopened this Mar 22, 2020
@quangngd quangngd changed the title EHN: to_html col_space col specific EHN: col_space col specific for to_html to_latex to_string Mar 22, 2020
@quangngd quangngd changed the title EHN: col_space col specific for to_html to_latex to_string EHN: to_{html, latex, string} col_space col specific Mar 22, 2020
@alimcmaster1
Copy link
Member

@quangngd you still interested in working on this?

@alimcmaster1 alimcmaster1 added IO HTML read_html, to_html, Styler.apply, Styler.applymap Enhancement labels May 2, 2020
@quangngd
Copy link
Contributor Author

quangngd commented May 3, 2020

@quangngd you still interested in working on this?

Yes, Im still waiting for feedbacks

@pep8speaks
Copy link

pep8speaks commented May 6, 2020

Hello @quangngd! 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 2020-06-18 06:38:51 UTC

@quangngd quangngd changed the title EHN: to_{html, latex, string} col_space col specific EHN: to_{html, string} col_space col specific May 6, 2020
@quangngd
Copy link
Contributor Author

quangngd commented May 6, 2020

Tests added for to_string.
Decided to drop to_latex due to lack of latex experience.
FYI, the current implementation for col_space in to_latex doesn't work either since it just simply add spaces between strings (like in to_string).

@alimcmaster1
Copy link
Member

@quangngd - thanks for the PR mind fixing up the test failures?

@quangngd
Copy link
Contributor Author

quangngd commented Jun 4, 2020

@alimcmaster1 done

@jreback jreback added this to the 1.1 milestone Jun 16, 2020
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.

lgtm. can you add a whatsnew note in 1.1. ping on green.

@jreback
Copy link
Contributor

jreback commented Jun 16, 2020

cc @WillAyd @simonjayhawkins for a look

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.

Implementation looks good. A few comments but mostly just minor typing / test clarifications

if col_space is None:
self.col_space = {}
elif isinstance(col_space, (int, str)):
self.col_space = {"": col_space}
Copy link
Member

Choose a reason for hiding this comment

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

Minor but you can just create the dict inline using a comprehension on one line instead of doing this then calling update on the next

Copy link
Contributor Author

@quangngd quangngd Jun 18, 2020

Choose a reason for hiding this comment

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

@WillAyd The "" (empty) key is for the row id column. Couldn't think of how to turn this into a oneliner?

@@ -702,7 +733,7 @@ def _to_str_columns(self) -> List[List[str]]:
"""
# this method is not used by to_html where self.col_space
# could be a string so safe to cast
self.col_space = cast(int, self.col_space)
col_space = {k: cast(int, v) for k, v in self.col_space.items()}
Copy link
Member

Choose a reason for hiding this comment

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

Is the cast still required here?

Copy link
Contributor Author

@quangngd quangngd Jun 18, 2020

Choose a reason for hiding this comment

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

@WillAyd Not an actual cast, typing.cast just used to signal to the type checker (mypy). In this case self.col_space can be of type dict<str> by definition but we are sure that it is dict<int> within this scope

@quangngd quangngd requested review from WillAyd and jreback June 18, 2020 07:21
@WillAyd WillAyd merged commit a07748f into pandas-dev:master Jun 18, 2020
@WillAyd
Copy link
Member

WillAyd commented Jun 18, 2020

Great PR - thanks a lot @quangngd !

@quangngd quangngd deleted the ehn-to_html-col_space branch June 20, 2020 11:08
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.

DataFrame.to_html col_space parameter to change width of a specific column only
6 participants