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

Incompatibility with talib (expected numpy.ndarray, got DataFrame) #2107

Open
finisky opened this issue Nov 2, 2024 · 2 comments
Open

Incompatibility with talib (expected numpy.ndarray, got DataFrame) #2107

finisky opened this issue Nov 2, 2024 · 2 comments

Comments

@finisky
Copy link

finisky commented Nov 2, 2024

Describe bug

talib cannot accept dataframe as input:

Traceback (most recent call last):
  File "/data/1.py", line 7, in <module>
    df['SMA_5'] = ta.SMA(df['Close'], timeperiod=5)
  File "/data/miniconda3/envs/a/lib/python3.10/site-packages/talib/__init__.py", line 64, in wrapper
    result = func(*_args, **_kwds)
TypeError: Argument 'real' has incorrect type (expected numpy.ndarray, got DataFrame)

It works for yf 0.2.44, but not work for 0.2.46+.

Simple code that reproduces your problem

import talib as ta
import yfinance as yf

df = yf.download("MSFT", period='5d')
df['SMA'] = ta.SMA(df['Close'], timeperiod=3)

Debug log

N/A

Bad data proof

No response

yfinance version

0.2.48

Python version

3.10.13

Operating system

Ubuntu 22.04

@ValueRaider
Copy link
Collaborator

It works for yf 0.2.44, but not work for 0.2.46+.

Double-check this. I get opposite.

@dhruvan2006
Copy link
Contributor

Cause:

After issues #2068 #2100 , yf.download("MSFT") returns by default now a DataFrame with an extra level Ticker

Fix:

Either use

df = yf.download("MSFT", period='5d', multi_level_index=False)

or

df = yf.Ticker("MSFT").history()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants