Skip to content

BUG: to_csv not respecting float_format for Float64 #46007

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 2 commits into from
Feb 16, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Feb 15, 2022

@phofl phofl added Bug IO CSV read_csv, to_csv labels Feb 15, 2022
@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Feb 16, 2022
@jreback jreback added this to the 1.5 milestone Feb 16, 2022
@jreback jreback merged commit 8db43ed into pandas-dev:main Feb 16, 2022
@jreback
Copy link
Contributor

jreback commented Feb 16, 2022

thank you @phofl

@mroeschke
Copy link
Member

@phofl I think this is failing on main on Windows builds https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=74146&view=logs&jobId=2b18e8df-2ee7-5e01-73e9-0533d995635b&j=2b18e8df-2ee7-5e01-73e9-0533d995635b&t=13dd5051-9e2f-5a32-09fe-1d338e0833eb

_________________ TestToCSV.test_to_csv_float_ea_float_format _________________
[gw1] win32 -- Python 3.10.2 C:\Miniconda\envs\pandas-dev\python.exe

self = <pandas.tests.io.formats.test_to_csv.TestToCSV object at 0x0000025FCC572B00>

        def test_to_csv_float_ea_float_format(self):
            # GH#45991
            df = DataFrame({"a": [1.1, 2.02, pd.NA, 6.000006], "b": "c"})
            df["a"] = df["a"].astype("Float64")
            result = df.to_csv(index=False, float_format="%.5f")
            expected = """a,b
    1.10000,c
    2.02000,c
    ,c
    6.00001,c
    """
>           assert result == expected
E           AssertionError: assert 'a,b\r\n1.100...6.00001,c\r\n' == 'a,b\n1.10000...\n6.00001,c\n'
E             - a,b
E             + a,b

E             ?    +
E             - 1.10000,c
E             + 1.10000,c

E             ?          +
E             - 2.02000,c...
E             
E             ?      +
E             - 2.02,c...
E             
E             ...Full output truncated (9 lines hidden), use '-vv' to show

@phofl
Copy link
Member Author

phofl commented Feb 16, 2022

Thx @mroeschke, opened #46024

@phofl phofl deleted the 45991 branch February 16, 2022 18:46
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas.DataFrame.to_csv float_format parameter not working as expected with pandas.Float64Dtype dtype
3 participants