Skip to content

Commit 5f3a8bb

Browse files
committed
DOC: Add ignore_functions option to validate_docstrings.py
1 parent 23c3676 commit 5f3a8bb

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

ci/code_checks.sh

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8383
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06
8484
RET=$(($RET + $?)) ; echo $MSG "DONE"
8585

86+
$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+
8688
fi
8789

8890
### DOCUMENTATION NOTEBOOKS ###

scripts/validate_docstrings.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def pandas_validate(func_name: str):
295295
return result
296296

297297

298-
def validate_all(prefix, ignore_deprecated=False):
298+
def validate_all(prefix, ignore_deprecated=False, ignore_functions=None):
299299
"""
300300
Execute the validation of all docstrings, and return a dict with the
301301
results.
@@ -307,6 +307,8 @@ def validate_all(prefix, ignore_deprecated=False):
307307
validated. If None, all docstrings will be validated.
308308
ignore_deprecated: bool, default False
309309
If True, deprecated objects are ignored when validating docstrings.
310+
ignore_functions: list of str or None, default None
311+
If not None, contains a list of function to ignore
310312
311313
Returns
312314
-------
@@ -317,6 +319,11 @@ def validate_all(prefix, ignore_deprecated=False):
317319
result = {}
318320
seen = {}
319321

322+
if ignore_functions is None:
323+
ignore_functions = {}
324+
else:
325+
ignore_functions = set(ignore_functions)
326+
320327
base_path = pathlib.Path(__file__).parent.parent
321328
api_doc_fnames = pathlib.Path(base_path, "doc", "source", "reference")
322329
api_items = []
@@ -325,7 +332,9 @@ def validate_all(prefix, ignore_deprecated=False):
325332
api_items += list(get_api_items(f))
326333

327334
for func_name, _, section, subsection in api_items:
328-
if prefix and not func_name.startswith(prefix):
335+
if (
336+
prefix and not func_name.startswith(prefix)
337+
) or func_name in ignore_functions:
329338
continue
330339
doc_info = pandas_validate(func_name)
331340
if ignore_deprecated and doc_info["deprecated"]:
@@ -353,11 +362,12 @@ def print_validate_all_results(
353362
errors: list[str] | None,
354363
output_format: str,
355364
ignore_deprecated: bool,
365+
ignore_functions: list[str] | None,
356366
):
357367
if output_format not in ("default", "json", "actions"):
358368
raise ValueError(f'Unknown output_format "{output_format}"')
359369

360-
result = validate_all(prefix, ignore_deprecated)
370+
result = validate_all(prefix, ignore_deprecated, ignore_functions)
361371

362372
if output_format == "json":
363373
sys.stdout.write(json.dumps(result))
@@ -408,13 +418,17 @@ def header(title, width=80, char="#"):
408418
sys.stderr.write(result["examples_errs"])
409419

410420

411-
def main(func_name, prefix, errors, output_format, ignore_deprecated):
421+
def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_functions):
412422
"""
413423
Main entry point. Call the validation for one or for all docstrings.
414424
"""
415425
if func_name is None:
416426
return print_validate_all_results(
417-
prefix, errors, output_format, ignore_deprecated
427+
prefix,
428+
errors,
429+
output_format,
430+
ignore_deprecated,
431+
ignore_functions,
418432
)
419433
else:
420434
print_validate_one_results(func_name)
@@ -464,6 +478,13 @@ def main(func_name, prefix, errors, output_format, ignore_deprecated):
464478
"deprecated objects are ignored when validating "
465479
"all docstrings",
466480
)
481+
argparser.add_argument(
482+
"--ignore_functions",
483+
default=None,
484+
help="function or method to not validate "
485+
"(e.g. Pandas.DataFrame.head). "
486+
"Inverse of the `function` argument.",
487+
)
467488

468489
args = argparser.parse_args()
469490
sys.exit(
@@ -473,5 +494,6 @@ def main(func_name, prefix, errors, output_format, ignore_deprecated):
473494
args.errors.split(",") if args.errors else None,
474495
args.format,
475496
args.ignore_deprecated,
497+
args.ignore_functions.split(",") if args.ignore_functions else None,
476498
)
477499
)

0 commit comments

Comments
 (0)