Indeed, nice catch!

I opened https://github.com/scipy/scipy_doctest/issues/213 to investigate a
fix for numpy, scipy et al.
Your pandas fix AFAIU might include unrelated objects (e.g.
builtins.float.__new__) but definitely `matrix.all` is missing otherwise.

While on the subject of the stdlib doctest deficiencies around methods of
objects, and in case it's relevant for pandas,
numpy had to work around doctests skipping member descriptors:
https://github.com/scipy/scipy_doctest/pull/180
This might be relevant if you assemble an object from C.

Cheers,

Evgeni


On Sun, Jan 4, 2026 at 7:48 PM Richard Shadrach via NumPy-Discussion <
[email protected]> wrote:

> I did a more systematic search and I think I found some cases. I'm not
> seeing methods of matrix such as np.matrix.all being run here:
>
>
> https://circleci.com/api/v1.1/project/github/numpy/numpy/51982/output/111/0?file=true&allocation-id=69343730dc0e375e9b03576e-0-build%2FABCDEFGH
>
> https://numpy.org/doc/stable/reference/generated/numpy.matrix.all.html#numpy-matrix-all
>
> Best,
> Richard
>
> On Sun, Jan 4, 2026 at 11:11 AM Richard Shadrach <[email protected]>
> wrote:
>
>> Similar to NumPy, pandas has modified the __module__ attribute of various
>> objects to point to their public location rather than where they are
>> defined in the code. Somewhat recently, we realized that this has silently
>> prevented many of our doctests from running. This is due to the __module__
>> of the class no longer agreeing with the __module__ of the methods on said
>> class. When this occurs, CPython skips running the doctest on the method
>> due to this check:
>>
>>
>> https://github.com/python/cpython/blob/9bf5100037f661f3a369d3ee539bec06f063b650/Lib/doctest.py#L1069-L1072
>>
>> since `self._from_module(module, val))` results in False. In pandas,
>> we've hacked our way around this check here:
>>
>>
>> https://github.com/pandas-dev/pandas/blob/91514c363604506f447e53380d3aa00520f1037b/pandas/conftest.py#L122-L131
>>
>> I've spot-checked a few of the doctest from a recent PR in NumPy, and
>> from what I can tell NumPy is _not_ impacted by this. It seems to me that
>> on classes where the __module__ is being modified, the doctests are still
>> running. However I have not been able to tell why this is, so I am sending
>> this only out of caution in case I've missed something.
>>
>> Best,
>> Richard
>>
>> _______________________________________________
> NumPy-Discussion mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
> Member address: [email protected]
>
_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]

Reply via email to