-
-
Couldn't load subscription status.
- Fork 19.2k
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
Conversation
# Conflicts: # pandas/io/formats/style.py # pandas/tests/io/formats/style/test_to_latex.py
|
@ivanovmg you fancy reviewing this one too? |
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.
Please see my comments below.
| ) | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is this conversion necessary?
It seems that A column is already of int type.
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.
correct seemed to be legacy code (from copy/paste)
| colspan = attrs[attrs.find('colspan="') + 9 :] # len('colspan="') = 9 | ||
| colspan = int(colspan[: colspan.find('"')]) | ||
| if "naive-l" == multicol_align: | ||
| out = f"{{{display_val}}}" if wrap else f"{display_val}" |
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 to siunitx?
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
| """ | ||
| ) | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Would you consider extracting result and then assert result == expected?
Also, it is better to avoid one-letter variables (s in this case) to make debugging easier.
| expected = dedent( | ||
| f"""\ | ||
| \\begin{{tabular}}{{l{"SS" if siunitx else "rr"}l}} | ||
| {exp} \\\\ |
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.
Does this exp actually refer to a header?
Will it be better if you call it header?
| ridx = MultiIndex.from_tuples([("A", "a"), ("A", "b"), ("A", "c")]) | ||
| df = df.astype({"A": int}) | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of having logic inside tests.
I would suggest to move level1 to pytest.mark.parametrize alongside siunitx.
But it may not fit nicely in one line with the other parameters, so may be leave it as it is.
| level1 = " & a & b & c" if not siunitx else "{} & {a} & {b} & {c}" | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
@ivanovmg changes made. I disagree with your philosophy on logic in tests. Personally I prefer parametrizations to focus as much as possible on as few parameters, and be an indicator to the purpose of the test. |
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
follows #43369