Skip to content

test: tests/no_imports_test.py::test_pyarrow may randomly fail #2367

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

Open
MarcoGorelli opened this issue Apr 9, 2025 · 1 comment
Open

Comments

@MarcoGorelli
Copy link
Member

Check this out:

(polars-api-compat-dev) marcogorelli@DESKTOP-U8OKFP3:~/polars-api-compat-dev$ pytest tests/no_imports_test.py 
=========================================== test session starts ===========================================
platform linux -- Python 3.12.9, pytest-8.3.5, pluggy-1.5.0
Using --randomly-seed=1694143034
rootdir: /home/marcogorelli/polars-api-compat-dev
configfile: pyproject.toml
plugins: anyio-4.9.0, env-1.1.5, cov-6.1.1, randomly-3.16.0, hypothesis-6.130.12
collected 4 items                                                                                         

tests/no_imports_test.py ..F.                                                                       [100%]

================================================ FAILURES =================================================
______________________________________________ test_pyarrow _______________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f8575198da0>

    def test_pyarrow(monkeypatch: pytest.MonkeyPatch) -> None:
        pytest.importorskip("pyarrow")
        import pyarrow as pa
    
        monkeypatch.delitem(sys.modules, "polars", raising=False)
        monkeypatch.delitem(sys.modules, "pandas")
        monkeypatch.delitem(sys.modules, "duckdb", raising=False)
        monkeypatch.delitem(sys.modules, "dask", raising=False)
        monkeypatch.delitem(sys.modules, "ibis", raising=False)
        monkeypatch.delitem(sys.modules, "pyspark", raising=False)
        df = pa.table({"a": [1, 2, 3], "b": [4, 5, 6]})
        nw.from_native(df).group_by("a").agg(nw.col("b").mean()).filter(nw.col("a") > 1)
        assert "polars" not in sys.modules
>       assert "pandas" not in sys.modules
E       AssertionError: assert 'pandas' not in {'__future__': <module '__future__' from '/usr/lib/python3.12/__future__.py'>, '__main__': <module '__main__' from '/h... '__main__' from '/home/marcogorelli/polars-api-compat-dev/.venv/bin/pytest'>, '_abc': <module '_abc' (built-in)>, ...}
E        +  where {'__future__': <module '__future__' from '/usr/lib/python3.12/__future__.py'>, '__main__': <module '__main__' from '/h... '__main__' from '/home/marcogorelli/polars-api-compat-dev/.venv/bin/pytest'>, '_abc': <module '_abc' (built-in)>, ...} = sys.modules

tests/no_imports_test.py:89: AssertionError
========================================= short test summary info =========================================
FAILED tests/no_imports_test.py::test_pyarrow - AssertionError: assert 'pandas' not in {'__future__': <module '__future__' from '/usr/lib/python3.12/_...
======================================= 1 failed, 3 passed in 1.45s =======================================
(polars-api-compat-dev) marcogorelli@DESKTOP-U8OKFP3:~/polars-api-compat-dev$ pytest tests/no_imports_test.py 
=============================================================== test session starts ===============================================================
platform linux -- Python 3.12.9, pytest-8.3.5, pluggy-1.5.0
Using --randomly-seed=4003032099
rootdir: /home/marcogorelli/polars-api-compat-dev
configfile: pyproject.toml
plugins: anyio-4.9.0, env-1.1.5, cov-6.1.1, randomly-3.16.0, hypothesis-6.130.12
collected 4 items                                                                                                                                 

tests/no_imports_test.py ....                                                                                                               [100%]

================================================================ 4 passed in 0.78s ================================================================

🤷 no idea why

maybe we should look into a solution like https://stackoverflow.com/a/65163627/4451315 ?

@dangotbanned
Copy link
Member

Since there were 4 tests collected, does this fail when 1 of them imports pandas and runs before the pyarrow test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants