-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
To latex position #35284
To latex position #35284
Conversation
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.
Thanks for the PR. Minor comment on test but otherwise I think this is OK
@@ -481,6 +482,23 @@ def test_to_latex_caption_label(self): | |||
""" | |||
assert result_l == expected_l | |||
|
|||
# test when only the label is provided | |||
result_p = df.to_latex(position=the_position) |
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.
Can you create this as its own test? Same comment with one below
Hello @WillAyd , thanks for the review ! I did the changes you asked for, but one test seems to have failed, I'm not sure it's related to what I've written Would you also want tests when the caption, the label and the position is given ? |
Just restarted the failure let's see |
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.
Mostly looks good, two small comments (but I wouldn't object to solving the self._table_float
one in a separate PR).
pandas/io/formats/latex.py
Outdated
# then write output in a nested table/tabular environment | ||
buf.write(f"\\begin{{table}}") |
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.
Any obvious reason why this was moved up here? I would find buf.write(f"\\begin{{table}}{position_}")
more readable that the write
below.
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.
The reason I did this was only because the line was getting too long, but I can write it as it was for sure.
Maybe we should unify the way it's done in _write_tabular_begin
and _write_longtable_begin
? But it may be nitpicking
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.
The reason I did this was only because the line was getting too long, but I can write it as it was for sure.
I do find it more readable - but if you want to break the line, you could do so at \n
, so after the position.
Maybe we should unify the way it's done in
_write_tabular_begin
and_write_longtable_begin
?
Wow... indeed the difference between _write_tabular_begin
and _write_longtable_begin
seems to amount to the environment name: unless I'm mistaken, the merge is definitely worth doing (same for _end
). By the way, if the function are unified feel free to move back the any([p is not None...
down there.
pandas/io/formats/latex.py
Outdated
self.caption is not None | ||
or self.label is not None | ||
or self.position is not None | ||
): |
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.
As this test grows, it would be better to have self._table_float = any([p is not None for p in (caption, label, position)])
inside __init__.py
, to be used both here and in _write_tabular_end
.
@toobaz I tried to match the two functions
|
pandas/io/formats/latex.py
Outdated
if self.position is None: | ||
position_ = "" | ||
else: | ||
position_ = f"[{self.position}]" |
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.
Duplicated lines?
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.
Right thanks !
My suggestion was actually to entirely suppress But this is not a strict necessity, at least in this PR. So if you prefer we can merge this PR after solving my last comment above. |
OK @toobaz I hadn't understood ! I tried doing something to resolve this, but I suggest doing it on a separate PR because I think it will get a bit messy. This work is currently on a branch of mine and we can look at it once this PR is merged |
Looks ready to merge to me. @WillAyd any idea on the two checks still failing? |
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 @jreback
Thanks @SylvainLan |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff