Skip to content

Commit 7d042ee

Browse files
committed
ruff format
1 parent b8186eb commit 7d042ee

File tree

1 file changed

+42
-55
lines changed

1 file changed

+42
-55
lines changed

pandas/tests/io/formats/test_to_excel.py

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -526,43 +526,30 @@ def test_styler_input_recognized(self, formatter_kwargs):
526526
assert formatter.df is df
527527
assert isinstance(formatter.style_converter, CSSToExcelConverter)
528528

529-
@pytest.mark.parametrize("columns", [
530-
["A","C"],
531-
["A","B","C"]
532-
])
529+
@pytest.mark.parametrize("columns", [["A", "C"], ["A", "B", "C"]])
533530
def test_column_missmatch(self, columns):
534531
"""Testing that we throw an error when the specified columns are not found"""
535532
df = DataFrame({"A": [1, 2], "B": [3, 4]})
536-
msg="Not all names specified in 'columns' are found"
533+
msg = "Not all names specified in 'columns' are found"
537534
with pytest.raises(KeyError, match=msg):
538535
ExcelFormatter(df, cols=columns)
539536

540-
@pytest.mark.parametrize("columns",[
541-
["C"],
542-
["D"],
543-
["C","D"]
544-
])
545-
def test_column_full_miss(self,columns):
537+
@pytest.mark.parametrize("columns", [["C"], ["D"], ["C", "D"]])
538+
def test_column_full_miss(self, columns):
546539
"""Testing that we throw an error when all of the columns are not in"""
547540
df = DataFrame({"A": [1, 2], "B": [3, 4]})
548-
msg="passes columns are not ALL present dataframe"
541+
msg = "passes columns are not ALL present dataframe"
549542
with pytest.raises(KeyError, match=msg):
550543
ExcelFormatter(df, cols=columns)
551544

552-
@pytest.mark.parametrize("merge_cells", [
553-
"1",
554-
"invalid",
555-
1,
556-
0
557-
])
545+
@pytest.mark.parametrize("merge_cells", ["1", "invalid", 1, 0])
558546
def test_merge_cells_not_bool_throws(self, merge_cells):
559547
"""Testing that we throw an error when merge_cells is not a boolean"""
560548
df = DataFrame({"A": [1, 2], "B": [3, 4]})
561549
msg = f"Unexpected value for {merge_cells=}."
562550
with pytest.raises(ValueError, match=msg):
563551
ExcelFormatter(df, merge_cells=merge_cells)
564552

565-
566553
@pytest.mark.parametrize(
567554
"val, na_rep, expected",
568555
[
@@ -594,9 +581,7 @@ def test_format_value_handles_float(self, val, float_format, inf_rep, expected):
594581
Test that _format_value correctly handles float values.
595582
"""
596583
df = DataFrame()
597-
formatter = ExcelFormatter(
598-
df, float_format=float_format, inf_rep=inf_rep
599-
)
584+
formatter = ExcelFormatter(df, float_format=float_format, inf_rep=inf_rep)
600585
result = formatter._format_value(val)
601586
assert result == expected
602587

@@ -616,26 +601,20 @@ def test_format_value_throws_for_tz_aware_dt(self):
616601
formatter._format_value(val)
617602

618603
def test_formated_header_mi_multi_index_throws(self):
619-
header = [
620-
("Cool", "A"), ("Cool", "B"),
621-
("Amazing", "C"), ("Amazing", "D")
622-
]
604+
header = [("Cool", "A"), ("Cool", "B"), ("Amazing", "C"), ("Amazing", "D")]
623605
columns = MultiIndex.from_tuples(header)
624606
rng = np.random.default_rng(42)
625-
df = DataFrame(
626-
rng.standard_normal((4, 4)),
627-
columns=columns
628-
)
607+
df = DataFrame(rng.standard_normal((4, 4)), columns=columns)
629608
formatter = ExcelFormatter(df, index=False)
630-
assert(formatter.columns.nlevels > 1 and not formatter.index)
609+
assert formatter.columns.nlevels > 1 and not formatter.index
631610
with pytest.raises(NotImplementedError):
632611
list(formatter._format_header_mi())
633612

634613
def test_returns_none_no_header(self):
635-
df = DataFrame({"A": [1,2], "B": [3,4]})
636-
formatter = ExcelFormatter(df,header=False)
637-
assert(not formatter._has_aliases)
638-
assert(list(formatter._format_header_mi()) == [])
614+
df = DataFrame({"A": [1, 2], "B": [3, 4]})
615+
formatter = ExcelFormatter(df, header=False)
616+
assert not formatter._has_aliases
617+
assert list(formatter._format_header_mi()) == []
639618

640619
@pytest.mark.parametrize(
641620
"df, merge_cells, expected_cells",
@@ -707,7 +686,6 @@ def test_format_header_mi_general(self, df, merge_cells, expected_cells):
707686
]
708687
assert result_tuples == expected_cells
709688

710-
711689
@pytest.mark.parametrize(
712690
"df, formatter_options, expected_cells",
713691
[
@@ -773,8 +751,8 @@ def test_format_header_regular_general(self, df, formatter_options, expected_cel
773751
{},
774752
[
775753
(1, 0, "idx", None, None), # Index label
776-
(2, 0, "r1", None, None), # Index value
777-
(2, 1, 10, None, None), # Body value
754+
(2, 0, "r1", None, None), # Index value
755+
(2, 1, 10, None, None), # Body value
778756
],
779757
),
780758
# Case 2: index=False
@@ -937,8 +915,10 @@ def test_format_hierarchical_rows_general(
937915
0,
938916
0,
939917
[
940-
(0, 0, 10), (1, 0, 20), # Column A
941-
(0, 1, 30), (1, 1, 40), # Column B
918+
(0, 0, 10),
919+
(1, 0, 20), # Column A
920+
(0, 1, 30),
921+
(1, 1, 40), # Column B
942922
],
943923
),
944924
# Case 2: With offsets
@@ -947,8 +927,10 @@ def test_format_hierarchical_rows_general(
947927
1, # Simulates index=True
948928
1, # Simulates header=True
949929
[
950-
(1, 1, 10), (2, 1, 20), # Column A
951-
(1, 2, 30), (2, 2, 40), # Column B
930+
(1, 1, 10),
931+
(2, 1, 20), # Column A
932+
(1, 2, 30),
933+
(2, 2, 40), # Column B
952934
],
953935
),
954936
],
@@ -975,12 +957,12 @@ def test_generate_body_general(self, df, coloffset, rowcounter, expected_cells):
975957
"inf_rep": "Infinity",
976958
},
977959
[
978-
"A", # Column header
979-
"idx", # Index header
980-
0, # Index value
981-
1, # Index value
982-
"NULL", # Formatted NaN
983-
1.23, # Formatted float
960+
"A", # Column header
961+
"idx", # Index header
962+
0, # Index value
963+
1, # Index value
964+
"NULL", # Formatted NaN
965+
1.23, # Formatted float
984966
],
985967
),
986968
# Case 2: No index or header
@@ -998,17 +980,22 @@ def test_generate_body_general(self, df, coloffset, rowcounter, expected_cells):
998980
),
999981
{"na_rep": "Missing"},
1000982
[
1001-
"c1", "c2", # Column headers
1002-
"A", "a",
1003-
"i1", "i2", # Index headers
1004-
1, "Missing", # Index values (NaT formatted)
1005-
"Missing", # Body value (NaN formatted)
983+
"c1",
984+
"c2", # Column headers
985+
"A",
986+
"a",
987+
"i1",
988+
"i2", # Index headers
989+
1,
990+
"Missing", # Index values (NaT formatted)
991+
"Missing", # Body value (NaN formatted)
1006992
],
1007993
),
1008994
],
1009995
)
1010-
def test_get_formatted_cells_integration(self, df, formatter_options,
1011-
expected_values):
996+
def test_get_formatted_cells_integration(
997+
self, df, formatter_options, expected_values
998+
):
1012999
"""
10131000
Integration test for get_formatted_cells to ensure it chains all
10141001
formatting methods and applies final value formatting correctly.

0 commit comments

Comments
 (0)