From f47c055c8fe866f54e684a147bc2cdc681304424 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 21 May 2022 11:05:42 -0400 Subject: [PATCH 1/4] DOC: Ignore certain doctest warnings --- pandas/conftest.py | 40 ++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 6 ++++++ 2 files changed, 46 insertions(+) diff --git a/pandas/conftest.py b/pandas/conftest.py index d330c2de9d23f..8cf45b8e5751c 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -105,6 +105,24 @@ def pytest_addoption(parser): ) +def ignore_doctest_warning(item, path, message): + """Ignore doctest warning. + + Parameters + ---------- + item : pytest.Item + pytest test item. + path : str + Module path to Python object, e.g. "pandas.core.frame.DataFrame.append". A + warning will be filtered when item.name ends with in given path. So it is + sufficient to specify e.g. "DataFrame.append". + message : str + Message to be filtered. + """ + if item.name.endswith(path): + item.add_marker(pytest.mark.filterwarnings(f"ignore:{message}")) + + def pytest_collection_modifyitems(items, config): skip_slow = config.getoption("--skip-slow") only_slow = config.getoption("--only-slow") @@ -117,13 +135,35 @@ def pytest_collection_modifyitems(items, config): (pytest.mark.db, "db", skip_db, "--skip-db"), ] + # Warnings from doctests that can be ignored; place reason in comment above. + # Each entry specifies (path, message) - see ignore_doctest_warning + ignored_doctest_warnings = [ + # Deprecations where the docstring will emit a warning + ("DataFrame.append", "The frame.append method is deprecated"), + ("Series.append", "The series.append method is deprecated"), + ("dtypes.common.is_categorical", "is_categorical is deprecated"), + ("Categorical.replace", "Categorical.replace is deprecated"), + ("dtypes.common.is_extension_type", "'is_extension_type' is deprecated"), + ("Index.is_mixed", "Index.is_mixed is deprecated"), + ("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"), + # Docstring divides by zero to show behavior difference + ("missing.mask_zero_div_zero", "divide by zero encountered"), + # Docstring demonstrates the call raises a warning + ("_validators.validate_axis_style_args", "Use named arguments"), + ] + for item in items: + if config.getoption("--doctest-modules") or config.getoption( "--doctest-cython", default=False ): # autouse=True for the add_doctest_imports can lead to expensive teardowns # since doctest_namespace is a session fixture item.add_marker(pytest.mark.usefixtures("add_doctest_imports")) + + for path, message in ignored_doctest_warnings: + ignore_doctest_warning(item, path, message) + # mark all tests in the pandas/tests/frame directory with "arraymanager" if "/frame/" in item.nodeid: item.add_marker(pytest.mark.arraymanager) diff --git a/pyproject.toml b/pyproject.toml index 030e6bc3c470c..2f09b003defc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,12 @@ doctest_optionflags = [ filterwarnings = [ "error:Sparse:FutureWarning", "error:The SparseArray:FutureWarning", + # Deprecation gives warning on import during pytest collection + "ignore:pandas.core.index is deprecated:FutureWarning:importlib", + "ignore:pandas.util.testing is deprecated:FutureWarning:importlib", + # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 + "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", + ] junit_family = "xunit2" markers = [ From 6a45a20f844af1eb1aaf25d8b71e2c91ea7313c7 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 21 May 2022 11:07:22 -0400 Subject: [PATCH 2/4] cleanup --- pandas/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 8cf45b8e5751c..f791dddd9a2a0 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -153,7 +153,6 @@ def pytest_collection_modifyitems(items, config): ] for item in items: - if config.getoption("--doctest-modules") or config.getoption( "--doctest-cython", default=False ): From 1e7094943a1baab81894ee0003d880d1f4b6e563 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 21 May 2022 11:08:38 -0400 Subject: [PATCH 3/4] comment --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index f791dddd9a2a0..bd362087fb302 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -136,7 +136,7 @@ def pytest_collection_modifyitems(items, config): ] # Warnings from doctests that can be ignored; place reason in comment above. - # Each entry specifies (path, message) - see ignore_doctest_warning + # Each entry specifies (path, message) - see the ignore_doctest_warning function ignored_doctest_warnings = [ # Deprecations where the docstring will emit a warning ("DataFrame.append", "The frame.append method is deprecated"), From 5b35ed17e58b940df15dae4e02866541a40bc6ee Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 21 May 2022 11:11:31 -0400 Subject: [PATCH 4/4] Type hints --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index bd362087fb302..1a740d40480b0 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -105,7 +105,7 @@ def pytest_addoption(parser): ) -def ignore_doctest_warning(item, path, message): +def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None: """Ignore doctest warning. Parameters