Skip to content
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

numpy.dtype attributes are not recognized #178

Open
ev-br opened this issue Dec 15, 2024 · 4 comments · May be fixed by #180
Open

numpy.dtype attributes are not recognized #178

ev-br opened this issue Dec 15, 2024 · 4 comments · May be fixed by #180
Labels
bug Something isn't working

Comments

@ev-br
Copy link
Member

ev-br commented Dec 15, 2024

numpy/numpy#28001 : np.dtype.kind docstring is not checked.

In [4]: type(np.dtype.kind)
Out[4]: member_descriptor

and this member_descriptor is not recognized as an inspect.routine by doctest.DoctestFinder._find. There are in fact several other something_descriptors in np.dtype methods, and they are also skipped:

In [3]: {v: type(getattr(np.dtype, v)) for v in dir(np.dtype)}
Out[3]: 
{'__bool__': wrapper_descriptor,
 '__class__': type,
 '__class_getitem__': builtin_function_or_method,
 '__delattr__': wrapper_descriptor,
 '__dir__': method_descriptor,
 '__doc__': str,
 '__eq__': wrapper_descriptor,
 '__format__': method_descriptor,
 '__ge__': wrapper_descriptor,
 '__getattribute__': wrapper_descriptor,
 '__getitem__': wrapper_descriptor,
 '__getstate__': method_descriptor,
 '__gt__': wrapper_descriptor,
 '__hash__': wrapper_descriptor,
 '__init__': wrapper_descriptor,
 '__init_subclass__': builtin_function_or_method,
 '__le__': wrapper_descriptor,
 '__len__': wrapper_descriptor,
 '__lt__': wrapper_descriptor,
 '__mul__': wrapper_descriptor,
 '__ne__': wrapper_descriptor,
 '__new__': builtin_function_or_method,
 '__reduce__': method_descriptor,
 '__reduce_ex__': method_descriptor,
 '__repr__': wrapper_descriptor,
 '__rmul__': wrapper_descriptor,
 '__setattr__': wrapper_descriptor,
 '__setstate__': method_descriptor,
 '__sizeof__': method_descriptor,
 '__str__': wrapper_descriptor,
 '__subclasshook__': builtin_function_or_method,
 'alignment': member_descriptor,
 'base': getset_descriptor,
 'byteorder': member_descriptor,
 'char': member_descriptor,
 'descr': getset_descriptor,
 'fields': getset_descriptor,
 'flags': member_descriptor,
 'hasobject': getset_descriptor,
 'isalignedstruct': getset_descriptor,
 'isbuiltin': getset_descriptor,
 'isnative': getset_descriptor,
 'itemsize': member_descriptor,
 'kind': member_descriptor,
 'metadata': getset_descriptor,
 'name': getset_descriptor,
 'names': getset_descriptor,
 'ndim': getset_descriptor,
 'newbyteorder': method_descriptor,
 'num': member_descriptor,
 'shape': getset_descriptor,
 'str': getset_descriptor,
 'subdtype': getset_descriptor,
 'type': NoneType}

@ev-br ev-br added bug Something isn't working enhancement New features w.r.t. the original refguide-check labels Dec 15, 2024
@ev-br
Copy link
Member Author

ev-br commented Dec 15, 2024

The fix is likely around https://github.com/scipy/scipy_doctest/blob/main/scipy_doctest/frontend.py#L99 or even in DTFinder.find : if an object is a class or a class instance, take its __dir__ and manually call find on these {method,getset}_descriptors.

cross-ref #177 which is specific to strategy=api, though.

@mattip
Copy link

mattip commented Dec 15, 2024

I think you can use inspect.isdatadescriptor?

@ev-br
Copy link
Member Author

ev-br commented Dec 15, 2024

Looks like it might work indeed:

In [5]: import inspect

In [6]: inspect.isdatadescriptor(np.dtype.kind)
Out[6]: True

In [7]: inspect.isdatadescriptor(np.dtype.fields)
Out[7]: True

@ev-br
Copy link
Member Author

ev-br commented Dec 15, 2024

I actually wonder what is different between np.dtype.newbyteorder and np.dtype.kind. Both are method_descriptor, but the former is collected in numpy/numpy#28001 (comment) but the latter isn't.

EDIT:

In [13]: inspect.isroutine(np.dtype.kind)
Out[13]: False

In [14]: inspect.isroutine(np.dtype.newbyteorder)
Out[14]: True

@ev-br ev-br removed the enhancement New features w.r.t. the original refguide-check label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants