8000 BUG: styler.format options and validator tests by attack68 · Pull Request #43341 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: styler.format options and validator tests #43341

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

Merged
merged 11 commits into from
Sep 6, 2021
Prev Previous commit
Next Next commit
test param
  • Loading branch information
attack68 committed Sep 2, 2021
commit 37a9b339f15040e277415dab138cd1b4a844f640
25 changes: 15 additions & 10 deletions pandas/tests/io/formats/style/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,23 @@ def test_precision_zero(df):
assert ctx["body"][1][2]["display_value"] == "-1"


def test_format_options_validator():
@pytest.mark.parametrize(
"formatter, exp",
[
(lambda x: f"{x:.3f}", "9.000"),
("{:.2f}", "9.00"),
({0: "{:.1f}"}, "9.0"),
(None, "9"),
],
)
def test_formatter_options_validator(formatter, exp):
df = DataFrame([[9]])
with option_context("styler.format.formatter", lambda x: f"{x:.3f}"):
assert " 9.000 " in df.style.to_latex()
with option_context("styler.format.formatter", "{:.2f}"):
assert " 9.00 " in df.style.to_latex()
with option_context("styler.format.formatter", {0: "{:.1f}"}):
assert " 9.0 " in df.style.to_latex()
with option_context("styler.format.formatter", None):
assert " 9 " in df.style.to_latex()
with option_context("styler.format.formatter", formatter):
assert f" {exp} " in df.style.to_latex()


def test_formatter_options_raises():
msg = "Value must have type"
with pytest.raises(ValueError, match=msg):
with option_context("styler.format.formatter", ["bad", "type"]):
df.style.to_latex()
DataFrame().style.to_latex()
0