-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_html() with formatters=<list> and max_cols fixed #28183
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
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,6 +656,10 @@ def _chk_truncate(self) -> None: | |
frame = concat( | ||
(frame.iloc[:, :col_num], frame.iloc[:, -col_num:]), axis=1 | ||
) | ||
# truncate formatter | ||
if is_list_like(self.formatters) and self.formatters: | ||
truncate_fmt = cast(List[Callable], self.formatters) | ||
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. Just out of curiosity what complain was this giving? cast doesn't seem necessary given assignment back to self.formatters but I may be missing something 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. 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. Hmm OK. I think this is somewhat misleading though as Does changing this annotation to 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. It's passes! Although it's necessary to import Sequences in typing and change the concat operation from self.formatters = fmt[slice] + fmt[slice] to self.formatters = [*fmt[slice],*fmt[slice]] . May I make a commit with theses changes? 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. Hmm what type fails if you keep the code as is but just change annotation? Want to make sure if we change that we have appropriate test coverage 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.
makes sense. At the moment we have a conflict between the documentation and the implementation. so that could be confusing matters. Also, the wording for to_latex is slightly different from to_string and to_html. they all share the same code. maybe we should have a at the moment, if the list is too short, it raises and if the list is too long it ignores the additional elements. however, with the slicing from the start and end, weird things might happen. 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. @gabriellm1 in summary.. we want to avoid the cast. so for now we should probably go with this would be consistent with the check in however, you would still need to do I think validating the length of the list should be done in this PR, but updating the docs is outside the scope so could be done as a follow-up. @WillAyd lmk if you disagree. 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. Cast is gone. Now what about length validation? 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. if we only do the length validation (and don't check that the parameter is not a string or that the items are callables) in this PR, then a separate function is probably unnecessary. so just raise with a message along the lines of "The 'formatters' parameter must be of length equal to the number of columns."? 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. I don't think I got it. The validation would happen in the same place I made the changes? And what did you mean with "raise with a message"? |
||
self.formatters = truncate_fmt[:col_num] + truncate_fmt[-col_num:] | ||
self.tr_col_num = col_num | ||
if truncate_v: | ||
# cast here since if truncate_v is True, max_rows_adj is not None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>A</th> | ||
<th>...</th> | ||
<th>D</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>1_mod</td> | ||
<td>...</td> | ||
<td>4</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>5_mod</td> | ||
<td>...</td> | ||
<td>8</td> | ||
</tr> | ||
<tr> | ||
<th>2</th> | ||
<td>9_mod</td> | ||
<td>...</td> | ||
<td>12</td> | ||
</tr> | ||
<tr> | ||
<th>3</th> | ||
<td>13_mod</td> | ||
<td>...</td> | ||
<td>16</td> | ||
</tr> | ||
</tbody> | ||
</table> |
Uh oh!
There was an error while loading. Please reload this page.