sumerc / yappi

Yet Another Python Profiler, but this time multithreading, asyncio and gevent aware.
MIT License
1.44k stars 72 forks source link

Matplotlib errors with TypeError: 'NoneType' object is not callable #97

Closed kmodexc closed 2 years ago

kmodexc commented 2 years ago

Using matplotlib, pandas and yappi together to throw an error:

[...]
File "C:\Users\xxx\source\repos\ErrorAnalytics\env\lib\site-packages\numpy\core\getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable

Example-code:

import pandas as pd
import matplotlib.pyplot as plt
import yappi

with yappi.run():
    dataset = pd.DataFrame(data={
        'x': list(range(10)),
        'y': list(range(10))})
    plt.plot(data=dataset)
    plt.savefig("fig.png")

yappi.get_func_stats().print_all()

I already posted on matplotlib here but it seems to be a problem from yappi.

sumerc commented 2 years ago

Hmmm. Interesting. I will be looking into this.

The relevant code in numpy:

try:
    dtype = numeric.dtype(dtype)
except TypeError:
    # In case a float instance was given
    dtype = numeric.dtype(type(dtype))

Weird. The first call to numeric.dtype throws TypeError and then None is not callable.

sumerc commented 2 years ago

FI: The issue only happens on Python 3.10. I have successfully profiled above in 3.9.

sumerc commented 2 years ago

Found the issue. It is this line causing the problem on Python 3.10: https://github.com/sumerc/yappi/blob/513513c8871f1dbdaa401cecd756254a160b2feb/yappi/_yappi.c#L661

I still do not know how PyFrame_FastToLocals mutates an object. I will need to dig a bit deeper to understand the root cause before proposing a fix.

sumerc commented 2 years ago

Issue is fixed in latest release: 1.3.5