1
1
"""Tests formatting as writer-agnostic ExcelCells"""
2
2
3
- import numpy as np
4
-
5
3
import string
4
+ from unittest .mock import (
5
+ Mock ,
6
+ call ,
7
+ patch ,
8
+ )
6
9
10
+ import numpy as np
7
11
import pytest
8
12
13
+ from pandas .errors import CSSWarning
14
+
9
15
from pandas import (
10
16
DataFrame ,
11
17
Index ,
12
18
MultiIndex ,
19
+ NaT ,
13
20
Timestamp ,
14
- NaT
15
21
)
16
- from pandas .errors import CSSWarning
17
-
18
22
import pandas ._testing as tm
19
23
20
24
from pandas .io .formats .excel import (
23
27
ExcelCell ,
24
28
ExcelFormatter ,
25
29
)
26
-
27
30
from pandas .io .formats .style import Styler
28
31
29
- from unittest .mock import Mock , patch , call
30
32
31
33
@pytest .mark .parametrize (
32
34
"css,expected" ,
@@ -581,7 +583,7 @@ def test_format_value_handles_na(self, val, na_rep, expected):
581
583
formatter = ExcelFormatter (df , na_rep = na_rep )
582
584
result = formatter ._format_value (val )
583
585
assert result == expected
584
-
586
+
585
587
@pytest .mark .parametrize (
586
588
"val, float_format, inf_rep, expected" ,
587
589
[
@@ -626,7 +628,7 @@ def test_formated_header_mi_multi_index_throws(self):
626
628
df = DataFrame (
627
629
np .random .randn (4 , 4 ),
628
630
columns = columns
629
- )
631
+ )
630
632
formatter = ExcelFormatter (df , index = False )
631
633
assert (formatter .columns .nlevels > 1 and not formatter .index )
632
634
msg = (
@@ -635,13 +637,13 @@ def test_formated_header_mi_multi_index_throws(self):
635
637
)
636
638
with pytest .raises (NotImplementedError ):
637
639
list (formatter ._format_header_mi ())
638
-
640
+
639
641
def test_returns_none_no_header (self ):
640
642
df = DataFrame ({"A" : [1 ,2 ], "B" : [3 ,4 ]})
641
643
formatter = ExcelFormatter (df ,header = False )
642
644
assert (formatter ._has_aliases == False )
643
645
assert (list (formatter ._format_header_mi ()) == list ())
644
-
646
+
645
647
@pytest .mark .parametrize (
646
648
"df, merge_cells, expected_cells" ,
647
649
[
@@ -840,7 +842,7 @@ def test_format_regular_rows_general(self, df, formatter_options, expected_cells
840
842
for cell in result
841
843
]
842
844
assert result_tuples == expected_cells
843
-
845
+
844
846
@pytest .mark .parametrize (
845
847
"df, formatter_options, expected_cells" ,
846
848
[
@@ -980,10 +982,10 @@ def test_generate_body_general(self, df, coloffset, rowcounter, expected_cells):
980
982
"inf_rep" : "Infinity" ,
981
983
},
982
984
[
983
- "A" , # Column header
985
+ "A" , # Column header
984
986
"idx" , # Index header
985
987
0 , # Index value
986
- 1 , # Index value
988
+ 1 , # Index value
987
989
"NULL" , # Formatted NaN
988
990
1.23 , # Formatted float
989
991
],
@@ -1022,4 +1024,4 @@ def test_get_formatted_cells_integration(self, df, formatter_options, expected_v
1022
1024
result_values = [cell .val for cell in result ]
1023
1025
1024
1026
assert result_values == expected_values
1025
- # Flatten the structure and check against expected formatted values
1027
+ # Flatten the structure and check against expected formatted values
0 commit comments