Skip to content

Commit 65f3169

Browse files
authored
DOC: Ignore certain doctest warnings (#47083)
1 parent 1be9d38 commit 65f3169

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pandas/conftest.py

+39
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ def pytest_addoption(parser):
105105
)
106106

107107

108+
def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None:
109+
"""Ignore doctest warning.
110+
111+
Parameters
112+
----------
113+
item : pytest.Item
114+
pytest test item.
115+
path : str
116+
Module path to Python object, e.g. "pandas.core.frame.DataFrame.append". A
117+
warning will be filtered when item.name ends with in given path. So it is
118+
sufficient to specify e.g. "DataFrame.append".
119+
message : str
120+
Message to be filtered.
121+
"""
122+
if item.name.endswith(path):
123+
item.add_marker(pytest.mark.filterwarnings(f"ignore:{message}"))
124+
125+
108126
def pytest_collection_modifyitems(items, config):
109127
skip_slow = config.getoption("--skip-slow")
110128
only_slow = config.getoption("--only-slow")
@@ -117,13 +135,34 @@ def pytest_collection_modifyitems(items, config):
117135
(pytest.mark.db, "db", skip_db, "--skip-db"),
118136
]
119137

138+
# Warnings from doctests that can be ignored; place reason in comment above.
139+
# Each entry specifies (path, message) - see the ignore_doctest_warning function
140+
ignored_doctest_warnings = [
141+
# Deprecations where the docstring will emit a warning
142+
("DataFrame.append", "The frame.append method is deprecated"),
143+
("Series.append", "The series.append method is deprecated"),
144+
("dtypes.common.is_categorical", "is_categorical is deprecated"),
145+
("Categorical.replace", "Categorical.replace is deprecated"),
146+
("dtypes.common.is_extension_type", "'is_extension_type' is deprecated"),
147+
("Index.is_mixed", "Index.is_mixed is deprecated"),
148+
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
149+
# Docstring divides by zero to show behavior difference
150+
("missing.mask_zero_div_zero", "divide by zero encountered"),
151+
# Docstring demonstrates the call raises a warning
152+
("_validators.validate_axis_style_args", "Use named arguments"),
153+
]
154+
120155
for item in items:
121156
if config.getoption("--doctest-modules") or config.getoption(
122157
"--doctest-cython", default=False
123158
):
124159
# autouse=True for the add_doctest_imports can lead to expensive teardowns
125160
# since doctest_namespace is a session fixture
126161
item.add_marker(pytest.mark.usefixtures("add_doctest_imports"))
162+
163+
for path, message in ignored_doctest_warnings:
164+
ignore_doctest_warning(item, path, message)
165+
127166
# mark all tests in the pandas/tests/frame directory with "arraymanager"
128167
if "/frame/" in item.nodeid:
129168
item.add_marker(pytest.mark.arraymanager)

pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ doctest_optionflags = [
4545
filterwarnings = [
4646
"error:Sparse:FutureWarning",
4747
"error:The SparseArray:FutureWarning",
48+
# Deprecation gives warning on import during pytest collection
49+
"ignore:pandas.core.index is deprecated:FutureWarning:importlib",
50+
"ignore:pandas.util.testing is deprecated:FutureWarning:importlib",
51+
# Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758
52+
"ignore:`np.MachAr` is deprecated:DeprecationWarning:numba",
53+
4854
]
4955
junit_family = "xunit2"
5056
markers = [

0 commit comments

Comments
 (0)