@@ -746,35 +746,35 @@ def test_to_csv_iterative_compression_buffer(compression):
746
746
747
747
def test_new_style_float_format_basic ():
748
748
df = DataFrame ({"A" : [1234.56789 , 9876.54321 ]})
749
- result = df .to_csv (float_format = "{:.2f}" )
749
+ result = df .to_csv (float_format = "{:.2f}" , lineterminator = " \n " )
750
750
expected = ",A\n 0,1234.57\n 1,9876.54\n "
751
751
assert result == expected
752
752
753
753
754
754
def test_new_style_float_format_thousands ():
755
755
df = DataFrame ({"A" : [1234.56789 , 9876.54321 ]})
756
- result = df .to_csv (float_format = "{:,.2f}" )
756
+ result = df .to_csv (float_format = "{:,.2f}" , lineterminator = " \n " )
757
757
expected = ',A\n 0,"1,234.57"\n 1,"9,876.54"\n '
758
758
assert result == expected
759
759
760
760
761
761
def test_new_style_scientific_format ():
762
762
df = DataFrame ({"A" : [0.000123 , 0.000456 ]})
763
- result = df .to_csv (float_format = "{:.2e}" )
763
+ result = df .to_csv (float_format = "{:.2e}" , lineterminator = " \n " )
764
764
expected = ",A\n 0,1.23e-04\n 1,4.56e-04\n "
765
765
assert result == expected
766
766
767
767
768
768
def test_new_style_with_nan ():
769
769
df = DataFrame ({"A" : [1.23 , np .nan , 4.56 ]})
770
- result = df .to_csv (float_format = "{:.2f}" , na_rep = "NA" )
770
+ result = df .to_csv (float_format = "{:.2f}" , na_rep = "NA" , lineterminator = " \n " )
771
771
expected = ",A\n 0,1.23\n 1,NA\n 2,4.56\n "
772
772
assert result == expected
773
773
774
774
775
775
def test_new_style_with_mixed_types ():
776
776
df = DataFrame ({"A" : [1.23 , 4.56 ], "B" : ["x" , "y" ]})
777
- result = df .to_csv (float_format = "{:.2f}" )
777
+ result = df .to_csv (float_format = "{:.2f}" , lineterminator = " \n " )
778
778
expected = ",A,B\n 0,1.23,x\n 1,4.56,y\n "
779
779
assert result == expected
780
780
@@ -783,7 +783,7 @@ def test_new_style_with_mixed_types_in_column():
783
783
df = DataFrame ({"A" : [1.23 , "text" , 4.56 ]})
784
784
with warnings .catch_warnings (record = True ):
785
785
warnings .simplefilter ("always" )
786
- result = df .to_csv (float_format = "{:.2f}" )
786
+ result = df .to_csv (float_format = "{:.2f}" , lineterminator = " \n " )
787
787
788
788
expected = ",A\n 0,1.23\n 1,text\n 2,4.56\n "
789
789
assert result == expected
@@ -803,56 +803,56 @@ def test_invalid_new_style_format_specifier():
803
803
804
804
def test_old_style_format_compatibility ():
805
805
df = DataFrame ({"A" : [1234.56789 , 9876.54321 ]})
806
- result = df .to_csv (float_format = "%.2f" )
806
+ result = df .to_csv (float_format = "%.2f" , lineterminator = " \n " )
807
807
expected = ",A\n 0,1234.57\n 1,9876.54\n "
808
808
assert result == expected
809
809
810
810
811
811
def test_callable_float_format_compatibility ():
812
812
df = DataFrame ({"A" : [1234.56789 , 9876.54321 ]})
813
- result = df .to_csv (float_format = lambda x : f"{ x :,.2f} " )
813
+ result = df .to_csv (float_format = lambda x : f"{ x :,.2f} " , lineterminator = " \n " )
814
814
expected = ',A\n 0,"1,234.57"\n 1,"9,876.54"\n '
815
815
assert result == expected
816
816
817
817
818
818
def test_no_float_format ():
819
819
df = DataFrame ({"A" : [1.23 , 4.56 ]})
820
- result = df .to_csv (float_format = None )
820
+ result = df .to_csv (float_format = None , lineterminator = " \n " )
821
821
expected = ",A\n 0,1.23\n 1,4.56\n "
822
822
assert result == expected
823
823
824
824
825
825
def test_large_numbers ():
826
826
df = DataFrame ({"A" : [1e308 , 2e308 ]})
827
- result = df .to_csv (float_format = "{:.2e}" )
827
+ result = df .to_csv (float_format = "{:.2e}" , lineterminator = " \n " )
828
828
expected = ",A\n 0,1.00e+308\n 1,inf\n "
829
829
assert result == expected
830
830
831
831
832
832
def test_zero_and_negative ():
833
833
df = DataFrame ({"A" : [0.0 , - 1.23456 ]})
834
- result = df .to_csv (float_format = "{:+.2f}" )
834
+ result = df .to_csv (float_format = "{:+.2f}" , lineterminator = " \n " )
835
835
expected = ",A\n 0,+0.00\n 1,-1.23\n "
836
836
assert result == expected
837
837
838
838
839
839
def test_unicode_format ():
840
840
df = DataFrame ({"A" : [1.23 , 4.56 ]})
841
- result = df .to_csv (float_format = "{:.2f}€" , encoding = "utf-8" )
841
+ result = df .to_csv (float_format = "{:.2f}€" , encoding = "utf-8" , lineterminator = " \n " )
842
842
expected = ",A\n 0,1.23€\n 1,4.56€\n "
843
843
assert result == expected
844
844
845
845
846
846
def test_empty_dataframe ():
847
847
df = DataFrame ({"A" : []})
848
- result = df .to_csv (float_format = "{:.2f}" )
848
+ result = df .to_csv (float_format = "{:.2f}" , lineterminator = " \n " )
849
849
expected = ",A\n "
850
850
assert result == expected
851
851
852
852
853
853
def test_multi_column_float ():
854
854
df = DataFrame ({"A" : [1.23 , 4.56 ], "B" : [7.89 , 0.12 ]})
855
- result = df .to_csv (float_format = "{:.2f}" )
855
+ result = df .to_csv (float_format = "{:.2f}" , lineterminator = " \n " )
856
856
expected = ",A,B\n 0,1.23,7.89\n 1,4.56,0.12\n "
857
857
assert result == expected
858
858
@@ -865,20 +865,20 @@ def test_invalid_float_format_type():
865
865
866
866
def test_new_style_with_inf ():
867
867
df = DataFrame ({"A" : [1.23 , np .inf , - np .inf ]})
868
- result = df .to_csv (float_format = "{:.2f}" , na_rep = "NA" )
868
+ result = df .to_csv (float_format = "{:.2f}" , na_rep = "NA" , lineterminator = " \n " )
869
869
expected = ",A\n 0,1.23\n 1,inf\n 2,-inf\n "
870
870
assert result == expected
871
871
872
872
873
873
def test_new_style_with_precision_edge ():
874
874
df = DataFrame ({"A" : [1.23456789 ]})
875
- result = df .to_csv (float_format = "{:.10f}" )
875
+ result = df .to_csv (float_format = "{:.10f}" , lineterminator = " \n " )
876
876
expected = ",A\n 0,1.2345678900\n "
877
877
assert result == expected
878
878
879
879
880
880
def test_new_style_with_template ():
881
881
df = DataFrame ({"A" : [1234.56789 ]})
882
- result = df .to_csv (float_format = "Value: {:,.2f}" )
882
+ result = df .to_csv (float_format = "Value: {:,.2f}" , lineterminator = " \n " )
883
883
expected = ',A\n 0,"Value: 1,234.57"\n '
884
884
assert result == expected
0 commit comments