-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: multirow
naive implementation Styler.to_latex
part1
#43369
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
multirow
naive implementation Styler.to_latex
multirow
naive implementation Styler.to_latex
part1
seems ok, ideally let's have a latex user comment here. umm @bashtage IIRC? |
cc @ivanovmg if any comments |
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 comments from my side, regarding the test.
As for the name of the kwarg, then on the one hand I would suggest "none" over "naive".
But on the other hand, considering the similar implementation for the multicolumns, "naive" seems to be fine (I mean, "none-left" and "none-right" would look bizarre, in case of multicols IMHO).
df.loc[2, :] = [2, -2.22, "de"] | ||
df = df.astype({"A": int}) |
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.
Consider simplifying the dataframe creation to this:
df = DataFrame(
{"A": [0, 1, 2], "B": [-0.61, -1.22, -2.22], "C": ["ab", "cd", "de"]},
index=ridx,
)
This way, it is clearer what the dataframe actually look like.
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.
used in multiple tests so I cleaned up module with a fixture
@@ -242,6 +242,25 @@ def test_multiindex_row(df): | |||
assert expected == s.to_latex(sparse_index=False) | |||
|
|||
|
|||
def test_multirow_naive(df): | |||
ridx = MultiIndex.from_tuples([("A", "a"), ("A", "b"), ("B", "c")]) |
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.
I suggest that the letters A
and B
should not be repeated in both the index and columns.
What if you use these for the index?
ridx = MultiIndex.from_tuples([("X", "x"), ("X", "y"), ("Z", "z")])
I guess it will be easier to differentiate from the columns.
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.
fully agree. silly oversight.
""" | ||
) | ||
s = df.style.format(precision=2) | ||
assert expected == s.to_latex(multirow_align="naive") |
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.
I suggest that result
variable is extracted:
result = s.to_latex(multirow_align="naive")
assert result == expected
Besides, s
is not a preferred variable name, because one-letter variables make debugging more complicated.
What about making it more explicit, styler
?
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.
yes cleaned up module wide (somewhat)
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.
Looks like a nice tests clean-up.
A couple of follow-up comments.
df = df.copy() | ||
df.loc[2, :] = [2, -2.22, "de"] | ||
df = df.astype({"A": int}) | ||
return df |
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.
What about just this?
return DataFrame({"A": [0, 1, 2], "B": [-0.61, -1.22, -2.22], "C": ["ab", "cd", "de"]})
I mean, there is probably no reason to couple two fixtures together.
|
||
|
||
def test_multirow_naive(df_ext): | ||
ridx = MultiIndex.from_tuples([("X", "x"), ("X", "x"), ("Y", "y")]) |
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.
Maybe better to avoid a duplicate in the tuples (like ("X", "x")
).
This would do:
[("X", "x"), ("X", "z"), ("Y", "y")]
sure. 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.
Looks good to me
…dev#43369) * multirow naive implementation * multirow naive implementation * fix tests * fixture * clean up tests with fixture * (ivanomg req) ref tests * ivoanovmg req Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
this is also for compatability with
DataFrame.to_latex
. #41649I think its a nice feature though, although opinions on the argument input choice are welcome. Maybe
"none"
is better than"naive"
.When implementing this for multicol there will be the option for left or right alignment, so the likes of
"naive-left"
or"naive-r"
will be used. see #43382