-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
@quangngd you still interested in working on this? |
Yes, Im still waiting for feedbacks |
Tests added for to_string. |
@quangngd - thanks for the PR mind fixing up the test failures? |
@alimcmaster1 done |
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.
lgtm. can you add a whatsnew note in 1.1. ping on green.
cc @WillAyd @simonjayhawkins for a look |
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.
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} |
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.
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
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.
@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()} |
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.
Is the cast still required here?
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.
@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
Great PR - thanks a lot @quangngd ! |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
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.