Skip to content

Warnings from IPython tab completion tests #29070

@TomAugspurger

Description

@TomAugspurger

At some point, IPython changed their code to be async. Now, our tests using their tab completion stuff causes warnings.

$ pytest pandas/tests/ -k test_tab_complete_warning 

================================================================================= warnings summary =================================================================================
pandas/tests/arrays/categorical/test_warnings.py::TestCategoricalWarnings::test_tab_complete_warning
  /Users/taugspurger/sandbox/pandas/pandas/tests/arrays/categorical/test_warnings.py:14: RuntimeWarning: coroutine 'InteractiveShell.run_code' was never awaited
    ip.run_code(code)

pandas/tests/frame/test_api.py::TestDataFrameMisc::test_tab_complete_warning
  /Users/taugspurger/sandbox/pandas/pandas/tests/frame/test_api.py:575: RuntimeWarning: coroutine 'InteractiveShell.run_code' was never awaited
    ip.run_code(code)

pandas/tests/indexes/test_base.py::TestIndex::test_tab_complete_warning
  /Users/taugspurger/sandbox/pandas/pandas/tests/indexes/test_base.py:2420: RuntimeWarning: coroutine 'InteractiveShell.run_code' was never awaited
    ip.run_code(code)

pandas/tests/series/test_api.py::TestSeriesMisc::test_tab_complete_warning
  /Users/taugspurger/sandbox/pandas/pandas/tests/series/test_api.py:508: RuntimeWarning: coroutine 'InteractiveShell.run_code' was never awaited
    ip.run_code(code)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================================================== 4 passed, 11 skipped, 62860 deselected, 4 warnings in 29.50s ===========================================================

There's a race condition between the completion of the ip.run_code(code) calls and the asserts later on. We need to explicitly wait for the ip.run_code(code) to finish before moving on with the test. The easiest way is to

  1. Mark the tests as async with the 3rd-party pytest-asyncio (need to add to the CI)
  2. Rewrite the tests to use async def.
  3. Add an await to the ip.run_code
diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py
index 998f8b6f7d..b471e1dc1e 100644
--- a/pandas/tests/series/test_api.py
+++ b/pandas/tests/series/test_api.py
@@ -499,13 +499,15 @@ class TestSeriesMisc(TestData, SharedWithSparse):
         for full_series in [pd.Series([1]), pd.Series(index=[1])]:
             assert not full_series.empty
 
-    def test_tab_complete_warning(self, ip):
+    @pytest.mark.asyncio
+    async def test_tab_complete_warning(self, ip):
         # https://github.com/pandas-dev/pandas/issues/16409
         pytest.importorskip("IPython", minversion="6.0.0")
         from IPython.core.completer import provisionalcompleter
 
         code = "import pandas as pd; s = pd.Series()"
-        ip.run_code(code)
+        await ip.run_code(code)
+
         with tm.assert_produces_warning(None):
             with provisionalcompleter("ignore"):
                 list(ip.Completer.completions("s.", 1))

This is currently blocked by #29034. Once we drop 3.5, we can use the async and await syntax. I forgot 3.5 had async / await.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Testingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions