@@ -526,43 +526,30 @@ def test_styler_input_recognized(self, formatter_kwargs):
526
526
assert formatter .df is df
527
527
assert isinstance (formatter .style_converter , CSSToExcelConverter )
528
528
529
- @pytest .mark .parametrize ("columns" , [
530
- ["A" ,"C" ],
531
- ["A" ,"B" ,"C" ]
532
- ])
529
+ @pytest .mark .parametrize ("columns" , [["A" , "C" ], ["A" , "B" , "C" ]])
533
530
def test_column_missmatch (self , columns ):
534
531
"""Testing that we throw an error when the specified columns are not found"""
535
532
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"
537
534
with pytest .raises (KeyError , match = msg ):
538
535
ExcelFormatter (df , cols = columns )
539
536
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 ):
546
539
"""Testing that we throw an error when all of the columns are not in"""
547
540
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"
549
542
with pytest .raises (KeyError , match = msg ):
550
543
ExcelFormatter (df , cols = columns )
551
544
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 ])
558
546
def test_merge_cells_not_bool_throws (self , merge_cells ):
559
547
"""Testing that we throw an error when merge_cells is not a boolean"""
560
548
df = DataFrame ({"A" : [1 , 2 ], "B" : [3 , 4 ]})
561
549
msg = f"Unexpected value for { merge_cells = } ."
562
550
with pytest .raises (ValueError , match = msg ):
563
551
ExcelFormatter (df , merge_cells = merge_cells )
564
552
565
-
566
553
@pytest .mark .parametrize (
567
554
"val, na_rep, expected" ,
568
555
[
@@ -594,9 +581,7 @@ def test_format_value_handles_float(self, val, float_format, inf_rep, expected):
594
581
Test that _format_value correctly handles float values.
595
582
"""
596
583
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 )
600
585
result = formatter ._format_value (val )
601
586
assert result == expected
602
587
@@ -616,26 +601,20 @@ def test_format_value_throws_for_tz_aware_dt(self):
616
601
formatter ._format_value (val )
617
602
618
603
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" )]
623
605
columns = MultiIndex .from_tuples (header )
624
606
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 )
629
608
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
631
610
with pytest .raises (NotImplementedError ):
632
611
list (formatter ._format_header_mi ())
633
612
634
613
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 ()) == []
639
618
640
619
@pytest .mark .parametrize (
641
620
"df, merge_cells, expected_cells" ,
@@ -707,7 +686,6 @@ def test_format_header_mi_general(self, df, merge_cells, expected_cells):
707
686
]
708
687
assert result_tuples == expected_cells
709
688
710
-
711
689
@pytest .mark .parametrize (
712
690
"df, formatter_options, expected_cells" ,
713
691
[
@@ -773,8 +751,8 @@ def test_format_header_regular_general(self, df, formatter_options, expected_cel
773
751
{},
774
752
[
775
753
(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
778
756
],
779
757
),
780
758
# Case 2: index=False
@@ -937,8 +915,10 @@ def test_format_hierarchical_rows_general(
937
915
0 ,
938
916
0 ,
939
917
[
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
942
922
],
943
923
),
944
924
# Case 2: With offsets
@@ -947,8 +927,10 @@ def test_format_hierarchical_rows_general(
947
927
1 , # Simulates index=True
948
928
1 , # Simulates header=True
949
929
[
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
952
934
],
953
935
),
954
936
],
@@ -975,12 +957,12 @@ def test_generate_body_general(self, df, coloffset, rowcounter, expected_cells):
975
957
"inf_rep" : "Infinity" ,
976
958
},
977
959
[
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
984
966
],
985
967
),
986
968
# Case 2: No index or header
@@ -998,17 +980,22 @@ def test_generate_body_general(self, df, coloffset, rowcounter, expected_cells):
998
980
),
999
981
{"na_rep" : "Missing" },
1000
982
[
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)
1006
992
],
1007
993
),
1008
994
],
1009
995
)
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
+ ):
1012
999
"""
1013
1000
Integration test for get_formatted_cells to ensure it chains all
1014
1001
formatting methods and applies final value formatting correctly.
0 commit comments