-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 4 commits
d7779b6
11ac603
121062f
20f9b31
f561651
1732772
318bc7b
6fa0b35
237bee2
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 |
---|---|---|
|
@@ -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")]) | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. used in multiple tests so I cleaned up module with a fixture |
||
df.index = ridx | ||
expected = dedent( | ||
"""\ | ||
\\begin{tabular}{llrrl} | ||
& & A & B & C \\\\ | ||
A & a & 0 & -0.61 & ab \\\\ | ||
& b & 1 & -1.22 & cd \\\\ | ||
B & c & 2 & -2.22 & de \\\\ | ||
\\end{tabular} | ||
""" | ||
) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I suggest that result = s.to_latex(multirow_align="naive")
assert result == expected Besides, 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. yes cleaned up module wide (somewhat) |
||
|
||
|
||
def test_multiindex_row_and_col(df): | ||
cidx = MultiIndex.from_tuples([("Z", "a"), ("Z", "b"), ("Y", "c")]) | ||
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
andB
should not be repeated in both the index and columns.What if you use these for the index?
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.