Skip to content

Commit 2db9420

Browse files
committed
fixup! fixup! fixup! DOC: Add ignore_functions option to validate_docstrings.py
1 parent 2396257 commit 2db9420

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

ci/code_checks.sh

+27-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,33 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8484
RET=$(($RET + $?)) ; echo $MSG "DONE"
8585

8686
MSG='Partially validate docstrings (RT02)' ; echo $MSG
87-
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=RT02 --ignore_functions=pandas.Series.align,pandas.Series.dt.total_seconds,pandas.Series.cat.rename_categories,pandas.Series.cat.reorder_categories,pandas.Series.cat.add_categories,pandas.Series.cat.remove_categories,pandas.Series.cat.remove_unused_categories,pandas.Index.all,pandas.Index.any,pandas.CategoricalIndex.rename_categories,pandas.CategoricalIndex.reorder_categories,pandas.CategoricalIndex.add_categories,pandas.CategoricalIndex.remove_categories,pandas.CategoricalIndex.remove_unused_categories,pandas.MultiIndex.drop,pandas.DatetimeIndex.to_pydatetime,pandas.TimedeltaIndex.to_pytimedelta,pandas.core.groupby.SeriesGroupBy.apply,pandas.core.groupby.DataFrameGroupBy.apply,pandas.io.formats.style.Styler.export,pandas.api.extensions.ExtensionArray.astype,pandas.api.extensions.ExtensionArray.dropna,pandas.api.extensions.ExtensionArray.isna,pandas.api.extensions.ExtensionArray.repeat,pandas.api.extensions.ExtensionArray.unique,pandas.DataFrame.align
87+
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=RT02 --ignore_functions \
88+
pandas.Series.align \
89+
pandas.Series.dt.total_seconds \
90+
pandas.Series.cat.rename_categories \
91+
pandas.Series.cat.reorder_categories \
92+
pandas.Series.cat.add_categories \
93+
pandas.Series.cat.remove_categories \
94+
pandas.Series.cat.remove_unused_categories \
95+
pandas.Index.all \
96+
pandas.Index.any \
97+
pandas.CategoricalIndex.rename_categories \
98+
pandas.CategoricalIndex.reorder_categories \
99+
pandas.CategoricalIndex.add_categories \
100+
pandas.CategoricalIndex.remove_categories \
101+
pandas.CategoricalIndex.remove_unused_categories \
102+
pandas.MultiIndex.drop \
103+
pandas.DatetimeIndex.to_pydatetime \
104+
pandas.TimedeltaIndex.to_pytimedelta \
105+
pandas.core.groupby.SeriesGroupBy.apply \
106+
pandas.core.groupby.DataFrameGroupBy.apply \
107+
pandas.io.formats.style.Styler.export \
108+
pandas.api.extensions.ExtensionArray.astype \
109+
pandas.api.extensions.ExtensionArray.dropna \
110+
pandas.api.extensions.ExtensionArray.isna \
111+
pandas.api.extensions.ExtensionArray.repeat \
112+
pandas.api.extensions.ExtensionArray.unique \
113+
pandas.DataFrame.align
88114
RET=$(($RET + $?)) ; echo $MSG "DONE"
89115

90116
fi

scripts/tests/test_validate_docstrings.py

+19
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,25 @@ def test_leftover_files_raises(self):
199199
self._import_path(klass="BadDocstrings", func="leftover_files")
200200
)
201201

202+
def test_validate_all_ignore_functions(self, monkeypatch):
203+
monkeypatch.setattr(
204+
validate_docstrings,
205+
"get_all_api_items",
206+
lambda: [
207+
(
208+
"pandas.DataFrame.align",
209+
"func",
210+
"current_section",
211+
"current_subsection",
212+
)
213+
],
214+
)
215+
result = validate_docstrings.validate_all(
216+
prefix=None,
217+
ignore_functions=["pandas.DataFrame.align"],
218+
)
219+
assert len(result) == 0
220+
202221
def test_validate_all_ignore_deprecated(self, monkeypatch):
203222
monkeypatch.setattr(
204223
validate_docstrings,

scripts/validate_docstrings.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,7 @@ def validate_all(prefix, ignore_deprecated=False, ignore_functions=None):
321321

322322
ignore_functions = set(ignore_functions or [])
323323

324-
base_path = pathlib.Path(__file__).parent.parent
325-
api_doc_fnames = pathlib.Path(base_path, "doc", "source", "reference")
326-
api_items = []
327-
for api_doc_fname in api_doc_fnames.glob("*.rst"):
328-
with open(api_doc_fname) as f:
329-
api_items += list(get_api_items(f))
324+
api_items = get_all_api_items()
330325

331326
for func_name, _, section, subsection in api_items:
332327
if func_name in ignore_functions:
@@ -354,6 +349,16 @@ def validate_all(prefix, ignore_deprecated=False, ignore_functions=None):
354349
return result
355350

356351

352+
def get_all_api_items():
353+
base_path = pathlib.Path(__file__).parent.parent
354+
api_doc_fnames = pathlib.Path(base_path, "doc", "source", "reference")
355+
api_items = []
356+
for api_doc_fname in api_doc_fnames.glob("*.rst"):
357+
with open(api_doc_fname) as f:
358+
api_items += list(get_api_items(f))
359+
return api_items
360+
361+
357362
def print_validate_all_results(
358363
prefix: str,
359364
errors: list[str] | None,
@@ -477,7 +482,7 @@ def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_fun
477482
)
478483
argparser.add_argument(
479484
"--ignore_functions",
480-
default=None,
485+
nargs="*",
481486
help="function or method to not validate "
482487
"(e.g. pandas.DataFrame.head). "
483488
"Inverse of the `function` argument.",
@@ -491,6 +496,6 @@ def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_fun
491496
args.errors.split(",") if args.errors else None,
492497
args.format,
493498
args.ignore_deprecated,
494-
args.ignore_functions.split(",") if args.ignore_functions else None,
499+
args.ignore_functions,
495500
)
496501
)

0 commit comments

Comments
 (0)