-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: multicol
naive implementation. part2
#43382
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
7920037
8ea7b0c
b1d8a27
c6666ca
8840b42
f730cff
49405e7
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 |
---|---|---|
|
@@ -302,6 +302,34 @@ def test_multiindex_row_and_col(df_ext): | |
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"multicol_align, siunitx, exp", | ||
[ | ||
("naive-l", False, " & A & &"), | ||
("naive-r", False, " & & & A"), | ||
("naive-l", True, "{} & {A} & {} & {}"), | ||
("naive-r", True, "{} & {} & {} & {A}"), | ||
], | ||
) | ||
def test_multicol_naive(df, multicol_align, siunitx, exp): | ||
ridx = MultiIndex.from_tuples([("A", "a"), ("A", "b"), ("A", "c")]) | ||
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. Is this conversion necessary? 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. correct seemed to be legacy code (from copy/paste) |
||
df.columns = ridx | ||
level1 = " & a & b & c" if not siunitx else "{} & {a} & {b} & {c}" | ||
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 am not a fan of having logic inside tests. |
||
expected = dedent( | ||
f"""\ | ||
\\begin{{tabular}}{{l{"SS" if siunitx else "rr"}l}} | ||
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. Same here. |
||
{exp} \\\\ | ||
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. Does this |
||
{level1} \\\\ | ||
0 & 0 & -0.61 & ab \\\\ | ||
1 & 1 & -1.22 & cd \\\\ | ||
\\end{{tabular}} | ||
""" | ||
) | ||
s = df.style.format(precision=2) | ||
assert expected == s.to_latex(multicol_align=multicol_align, siunitx=siunitx) | ||
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. Would you consider extracting |
||
|
||
|
||
def test_multi_options(df_ext): | ||
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.
Is this
wrap
related tosiunitx
?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. the only time wrap is needed is when
siunitx
is True, but it only applies to columns headers, and not row headers, due to siunitx package establishing display properties for columns