Skip to content

BLD: validate_docstrings.py add ignore_known_fail argument #25617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import importlib
import doctest
import tempfile
import configparser
import itertools
import ast
import textwrap

Expand Down Expand Up @@ -156,6 +158,19 @@ def error(code, **kwargs):
return (code, ERROR_MSGS[code].format(**kwargs))


def get_setupcfg():
"""
Returns a ConfigParser which reads the setup.cfg file in the root
directory.
"""
setup_cfg = os.path.join(BASE_PATH, 'setup.cfg')
config = configparser.ConfigParser(inline_comment_prefixes='#')
config.optionxform = str
with open(setup_cfg, 'r') as file:
config.read_file(file)
return config


def get_api_items(api_doc_fd):
"""
Yield information about all public API items.
Expand Down Expand Up @@ -811,7 +826,7 @@ def validate_one(func_name):
'examples_errors': examples_errs}


def validate_all(prefix, ignore_deprecated=False):
def validate_all(prefix, ignore_deprecated=False, ignore_known_fail=False):
"""
Execute the validation of all docstrings, and return a dict with the
results.
Expand All @@ -832,6 +847,9 @@ def validate_all(prefix, ignore_deprecated=False):
"""
result = {}
seen = {}
if ignore_known_fail:
config = get_setupcfg()
known_fails = dict(config.items('known_fail'))

# functions from the API docs
api_doc_fnames = os.path.join(
Expand All @@ -846,6 +864,12 @@ def validate_all(prefix, ignore_deprecated=False):
doc_info = validate_one(func_name)
if ignore_deprecated and doc_info['deprecated']:
continue
if ignore_known_fail and func_name in known_fails:
doc_info['errors'] = list(itertools.filterfalse(
lambda x: x[0] in known_fails[func_name].split(','),
doc_info['errors']))
if not doc_info['errors']:
continue
result[func_name] = doc_info

shared_code_key = doc_info['file'], doc_info['file_line']
Expand All @@ -869,13 +893,20 @@ def validate_all(prefix, ignore_deprecated=False):
doc_info = validate_one(func_name)
if ignore_deprecated and doc_info['deprecated']:
continue
if ignore_known_fail and func_name in known_fails:
doc_info['errors'] = list(itertools.filterfalse(
lambda x: x[0] in known_fails[func_name].split(','),
doc_info['errors']))
if not doc_info['errors']:
continue
result[func_name] = doc_info
result[func_name]['in_api'] = False

return result


def main(func_name, prefix, errors, output_format, ignore_deprecated):
def main(func_name, prefix, errors, output_format, ignore_deprecated,
ignore_known_fail):
def header(title, width=80, char='#'):
full_line = char * width
side_len = (width - len(title) - 2) // 2
Expand All @@ -889,7 +920,7 @@ def header(title, width=80, char='#'):

exit_status = 0
if func_name is None:
result = validate_all(prefix, ignore_deprecated)
result = validate_all(prefix, ignore_deprecated, ignore_known_fail)

if output_format == 'json':
output = json.dumps(result)
Expand Down Expand Up @@ -984,9 +1015,14 @@ def header(title, width=80, char='#'):
action='store_true', help='if this flag is set, '
'deprecated objects are ignored when validating '
'all docstrings')
argparser.add_argument('--ignore_known_fail', default=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on the default? I would expect that if you're whitelisting thees failures, you wouldn't need to also pass --ignore-known-fail. Not a big deal either way since this is just in CI.

Can you add a couple sentences to contributing_docstring.rst saying when and how to use this?

action='store_true', help='if this flag is set, '
'objects listed in setup.cfg as known_fail are '
'ignored when validating all docstrings')

args = argparser.parse_args()
sys.exit(main(args.function, args.prefix,
args.errors.split(',') if args.errors else None,
args.format,
args.ignore_deprecated))
args.ignore_deprecated,
args.ignore_known_fail))
23 changes: 23 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,26 @@ skip=
pandas/_libs/tslibs/__init__.py
pandas/util/__init__.py
pandas/arrays/__init__.py

[scripts:validate_docstrings]
[known_fail]
# function_name = comma separated error_codes commented reason for ignoring
pandas.Timestamp.ctime = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.date = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.dst = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.isocalendar = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.isoweekday = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.strftime = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.strptime = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.time = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.timestamp = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.timetuple = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.timetz = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.toordinal = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.tzname = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.utcoffset = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.utctimetuple = GL01,GL02 # inherits from cpython datetime library
pandas.Timestamp.weekday = GL01,GL02 # inherits from cpython datetime library
pandas.Timedelta.days = GL01,GL02 # inherits from cpython datetime library
pandas.Timedelta.microseconds = GL01,GL02 # inherits from cpython datetime library
pandas.Timedelta.seconds = GL01,GL02 # inherits from cpython datetime library