Skip to content

Instantly share code, notes, and snippets.

@luxedo
Last active June 6, 2024 01:09
Show Gist options
  • Save luxedo/c7ad85b8848136671d126cd7baa07990 to your computer and use it in GitHub Desktop.
Save luxedo/c7ad85b8848136671d126cd7baa07990 to your computer and use it in GitHub Desktop.
"""
Adapted from
https://github.com/bmwoodruff/numpy-ideas/blob/main/find_numpy_functions_missing_examples.ipynb
Which adapted from
https://gist.github.com/WarrenWeckesser/c33d0236279cc5d73843f0497e14ed0e
Gotta giv'em credits 😉
Find numpy functions whose docstrings do not contain "Examples".
"""
import numpy as np
import types
import inspect
modules = [
'np',
'np.char',
# 'np.compat',
'np.ctypeslib',
'np.emath',
'np.fft',
'np.lib',
'np.linalg',
'np.ma',
'np.polynomial',
'np.random',
'np.random.Generator',
'np.rec',
'np.strings',
# 'np.testing',
]
skip = []
print(f"NumPy version {np.__version__}")
print()
#Dyanamically get 'numpy._ArrayFunctionDispatcher' as a type to check for.
dispatcher_type = type(getattr(eval('np.linalg'),'matrix_power'))
print(dispatcher_type)
total = 0
all_funcs = []
for module_name in modules:
mod = eval(module_name)
#print(mod)
objects = [(name,getattr(mod, name))
for name in getattr(mod, '__all__', dir(mod))
if not name.startswith('_')]
#print(objects)
#for item in objects: print(inspect.isroutine(item[1]))
funcs = [item for item in objects
if isinstance(item[1], (types.FunctionType,
types.BuiltinFunctionType,
types.MethodDescriptorType,
np.ufunc,
dispatcher_type,
))]
# funcs = [item for item in objects
# if inspect.isroutine(item[1])]
noex = [item for item in funcs
if ((module_name + '.' + item[0]) not in skip and
(item[1].__doc__ is None or
("is deprecated" not in item[1].__doc__) and
("Examples" not in item[1].__doc__)))]
noex = [item for item in noex if item not in all_funcs]
if len(noex) > 0:
all_funcs.extend(noex)
noex.sort()
total += len(noex)
print(module_name, "(%d)" % len(noex))
for name, func in noex:
print(" ", name, end='')
if func.__doc__ is None:
print(" \t[no docstring]")
else:
print()
print('Found %d functions' % total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment