AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'
Hello,
Thank you creating this project and making this open source.
I was just running through the readme.md file in vscode jupyter notebook but received an error.
Python 3.12.5
import matplotlib
%matplotlib inline
import quantstats as qs
# extend pandas functionality with metrics, etc.
qs.extend_pandas()
# fetch the daily returns for a stock
stock = qs.utils.download_returns('META')
# show sharpe ratio
qs.stats.sharpe(stock)
# or using extend_pandas() :)
stock.sharpe()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 4
1 import matplotlib
2 get_ipython().run_line_magic('matplotlib', 'inline')
----> 4 import quantstats as qs
6 # extend pandas functionality with metrics, etc.
7 qs.extend_pandas()
File c:\Users\Admin\Desktop\document\.venv\Lib\site-packages\quantstats\__init__.py:31
28 __all__ = ["stats", "plots", "reports", "utils", "extend_pandas"]
30 # try automatic matplotlib inline
---> 31 utils._in_notebook(matplotlib_inline=True)
34 def extend_pandas():
35 """
36 Extends pandas by exposing methods to be used like:
37 df.sharpe(), df.best('day'), ...
38 """
File c:\Users\Admin\Desktop\document\.venv\Lib\site-packages\quantstats\utils.py:310, in _in_notebook(matplotlib_inline)
307 if shell == "ZMQInteractiveShell":
308 # Jupyter notebook or qtconsole
309 if matplotlib_inline:
--> 310 get_ipython().magic("matplotlib inline")
311 return True
312 if shell == "TerminalInteractiveShell":
313 # Terminal running IPython
AttributeError: 'ZMQInteractiveShell' object has no attribute 'magic'
Please push the fix! I am fixing this by hand in my codebase. And yes, I have quantstats 0.0.64. The only change in utils.py from 63 -> 64 seems to be a change in the version number, no "magic" fix.
I've created a fork and made a release. In addition to fixing this bug (Python 3.12 support), I've also added compatibility for Python 3.13. I forked the project and published it as quantstats-reloaded to ensure more active updates and maintenance of the library.
Please find release at https://pypi.org/project/quantstats-reloaded/