Skip to content

CI: Change flaky to_excel test to use xlsxwriter #49509

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 7 commits into from
Nov 9, 2022

Conversation

mroeschke
Copy link
Member

test_write_fspath_all has been flaky and failing when comparing the binary xml for to_excel with openpyxl e.g.

_ TestCommonIOCapabilities.test_write_fspath_all[to_excel-writer_kwargs1-openpyxl] _
[gw2] darwin -- Python 3.9.13 /Users/runner/micromamba/envs/test/bin/python3.9

self = <pandas.tests.io.test_common.TestCommonIOCapabilities object at 0x157198af0>
writer_name = 'to_excel', writer_kwargs = {'engine': 'openpyxl'}
module = 'openpyxl'

    @pytest.mark.filterwarnings("ignore:In future versions `DataFrame.to_latex`")
    @pytest.mark.parametrize(
        "writer_name, writer_kwargs, module",
        [
            ("to_csv", {}, "os"),
            ("to_excel", {"engine": "openpyxl"}, "openpyxl"),
            ("to_feather", {}, "pyarrow"),
            ("to_html", {}, "os"),
            ("to_json", {}, "os"),
            ("to_latex", {}, "os"),
            ("to_pickle", {}, "os"),
            ("to_stata", {"time_stamp": pd.to_datetime("2019-01-01 00:00")}, "os"),
        ],
    )
    def test_write_fspath_all(self, writer_name, writer_kwargs, module):
        p1 = tm.ensure_clean("string")
        p2 = tm.ensure_clean("fspath")
        df = pd.DataFrame({"A": [1, 2]})
    
        with p1 as string, p2 as fspath:
            pytest.importorskip(module)
            mypath = CustomFSPath(fspath)
            writer = getattr(df, writer_name)
    
            writer(string, **writer_kwargs)
            with open(string, "rb") as f:
                expected = f.read()
    
            writer(mypath, **writer_kwargs)
            with open(fspath, "rb") as f:
                result = f.read()
    
>           assert result == expected
E           assert b'PK\x03\x04\...0\x00\x00\x00' == b'PK\x03\x04\...0\x00\x00\x00'
E             At index 10 diff: b'\x13' != b'\x12'
E             Full diff:
E               (
E             -  b'PK\x03\x04\x14\x00\x00\x00\x08\x00\x12xbU\x07AMb\x81\x00\x00\x00\xb1\x00'
E             ?                                         ^
E             +  b'PK\x03\x04\x14\x00\x00\x00\x08\x00\x13xbU\x07AMb\x81\x00\x00\x00\xb1\x00'
E             ?           

This was changed from xlwt to openpyxl in #49296, seeing if xlsxwriter is more stable.

@mroeschke mroeschke added IO Excel read_excel, to_excel Unreliable Test Unit tests that occasionally fail labels Nov 3, 2022
@rhshadrach
Copy link
Member

Guessing this should now pass with openpyxl as well as xlsxwriter now that we aren't comparing all file contents. Would it make sense to still test openpyxl, or is that redundant?

@mroeschke
Copy link
Member Author

I think testing both openpyxl and xlsxwriter would be redundant since it seem the main point of the test is to test a CustomFSPath

I changed it back to testing openpyxl.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rhshadrach rhshadrach added this to the 2.0 milestone Nov 9, 2022
@rhshadrach rhshadrach merged commit 61ba5f8 into pandas-dev:main Nov 9, 2022
@rhshadrach
Copy link
Member

Thanks @mroeschke

@mroeschke mroeschke deleted the ci/flaky/excel branch November 9, 2022 20:22
codamuse pushed a commit to codamuse/pandas that referenced this pull request Nov 12, 2022
mliu08 pushed a commit to mliu08/pandas that referenced this pull request Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Excel read_excel, to_excel Unreliable Test Unit tests that occasionally fail
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants