Closed peterxie1 closed 1 year ago
lol, just saw the same problem and spent an hour debugging.
It happens with pandas version 1.4 which is just released yesterday.
To workaround it, you can install pip install pandas==1.3.5
.
But yeah, it's a problem that needs a fix when using pandas 1.4
Thanks for the note! yes, downgrading pandas from 1.4 to 1.3.5 worked-around this issue.
yes, same issue here!
same issue here
same here, had to roll back the pandas version
lol, just saw the same problem and spent an hour debugging. It happens with pandas version 1.4 which is just released yesterday. To workaround it, you can install
pip install pandas==1.3.5
. But yeah, it's a problem that needs a fix when using pandas 1.4
Thanks!
I also tried downgrading yfinance to older versions - it didn't work. There were other changes on pandas 1.4 that required some adjustments on other parts of my code - maybe this update is a broader one.
I faced the same problem. It might be related to pandas change: "Ignoring dtypes in concat with empty or all-NA columns" The problem seams to in df = _pd.concat([quotes, dividends, splits], axis=1, sort=True)
df.intext.dtype=object in pandas 1.4 because dividends and splits are empty. With pandas 1.3.5 df.intext.dtype=datetime64[ns]
Hi @mundus08 , I am a newbie in the deployment domain. I was curious how you find the exact lines which might be the solution to the problem we are facing. So, did you go through the entire code for pandas to find the prospective lines which can be causing the trouble?
Hi @Dharmik-19 the stack trace contained the line number where the problem occured in yfinance. Then I added some print statements to the code and found out that the index dtype has changed. I suspected that it was due to the concat statement (because the dtype of the quotes df was still correct). In the release notes of pandas 1.4 I found a reference to the changes in the concat method.
Duplicate of https://github.com/ranaroussi/yfinance/issues/937 I believe.
Although #937 was closed, I still get an error message after updating Python/Pandas. I run the file test_yfinance.py and here are the results:
Traceback (most recent call last): File "C:\Users\danil\OneDrive\Python_projects\RIM_trading\untitled0.py", line 44, in test_attributes ticker.dividends File "C:\Users\danil\anaconda3\envs\spyder-5.2.2\lib\site-packages\yfinance\ticker.py", line 131, in dividends return self.get_dividends() File "C:\Users\danil\anaconda3\envs\spyder-5.2.2\lib\site-packages\yfinance\base.py", line 692, in get_dividends self.history(period="max", proxy=proxy) File "C:\Users\danil\anaconda3\envs\spyder-5.2.2\lib\site-packages\yfinance\base.py", line 295, in history df.index = df.index.tz_localize("UTC").tz_convert( AttributeError: 'Index' object has no attribute 'tz_localize'
Traceback (most recent call last): File "C:\Users\danil\OneDrive\Python_projects\RIM_trading\untitled0.py", line 35, in test_info_history history = ticker.history(period="max") File "C:\Users\danil\anaconda3\envs\spyder-5.2.2\lib\site-packages\yfinance\base.py", line 295, in history df.index = df.index.tz_localize("UTC").tz_convert( AttributeError: 'Index' object has no attribute 'tz_localize'
Ran 3 tests in 20.653s
FAILED (errors=2)
Confirm downgrading to pandas 1.3.5 solved the issue.
any updates on a fix?
The pandas downgrade worked for me as well. I'm looking forward to a fix for 1.4x.
Does this still happen in the latest release?
For me it was still causing the issue even after install panadas 1.3.5 But then I printed the version and came to know it wasnt using pandas 1.3.5 I had to restart the kernal of jupyter notebook in order to get the defined version. Hope this will help someone who is facing the similar issue.
!pip install yfinance
!pip install -U pandas==1.3.5
import yfinance as yf
import pandas as pd
import sys
print("Python Version", sys.version)
print("Yahoo Fianance lib : ", yf.__version__)
print("Panadas : ", pd.__version__)
Python Version 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] Yahoo Finance : 0.1.67 Panadas : 1.5.1
Thank you, pandas==1.3.5
worked
@wgong Can you provide code that was failing before you downgraded Pandas? We want to fix this problem but we can't reproduce.
@ValueRaider I just upgraded pandas back to 1.5.1, and cannot reproduced it either.
Here is my function which failed before
def gwg_download_yf(tickers, start_dt, end_dt=""):
"""download quotes of multiple tickers for given start_dt, end_dt (exclusive)
Args:
tickers (list)
start_dt (str) - YYYYMMDD
end_dt (str) - YYYYMMDD, optional. If end_dt = "", will download one date at start_dt
Returns:
dataframe or None
"""
df_ = None
if len(tickers) < 1:
return df_
start_date = datetime.strptime(start_dt, "%Y%m%d")
if not end_dt:
end_date = start_date + timedelta(days=1)
else:
end_date = datetime.strptime(end_dt, "%Y%m%d")
data = yf.download(" ".join(tickers),
start=datetime.strftime(start_date, "%Y-%m-%d"),
end=datetime.strftime(end_date, "%Y-%m-%d"))
return data
@ValueRaider I tried on a different Ubuntu computer, and cannot reproduce the initial error.
I downgraded to 1.3.5 and restarted the kernel but I am still getting the same error
AttributeError Traceback (most recent call last) Input In [10], in <cell line: 3>() 1 #Question 3 Obtain stock data for AMD using the history function, set the period to max. 2 #Find the Volume traded on the first day (first row). ----> 3 amd_stock_data = amd.history(period="max")
File ~\anaconda3\lib\site-packages\yfinance\base.py:279, in TickerBase.history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz, timeout, **kwargs) 276 df["Stock Splits"].fillna(0, inplace=True) 278 # index eod/intraday --> 279 df.index = df.index.tz_localize("UTC").tz_convert( 280 data["chart"]["result"][0]["meta"]["exchangeTimezoneName"]) 282 if params["interval"][-1] == "m": 283 df.index.name = "Datetime"
AttributeError: 'Index' object has no attribute 'tz_localize'
please help....
That looks like old code. Update yfinance to latest version, confirm with import yfinance as yf ; print(yf.__version__)
I checked version and it says 0.1.67
It works fine now, I just realized the version of the pandas was not changing , I was installing it the wrong way. So, I got the correct installation and it worked
Restarted Kernel;
!pip install yfinance !pip install -U pandas==1.3.5
Confirmed
Confirmed
Confirmed what?
Also everyone should be able to use any version of Pandas >=1.3.0 without problems.
In my case downgrading the pandas version to 1.3.5 is not working same error how can i resolve this
For me it was still causing the issue even after install panadas 1.3.5 But then I printed the version and came to know it wasnt using pandas 1.3.5 I had to restart the kernal of jupyter notebook in order to get the defined version. Hope this will help someone who is facing the similar issue.
!pip install yfinance !pip install -U pandas==1.3.5 import yfinance as yf import pandas as pd import sys print("Python Version", sys.version) print("Yahoo Fianance lib : ", yf.__version__) print("Panadas : ", pd.__version__)
Python Version 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] Yahoo Finance : 0.1.67 Panadas : 1.5.1
@Abdul675 please refer to this
@Abdul675 Try branch fix/prices-index-not-datetime
(instructions #1080) and give feedback.
Is this fixed in latest release 0.2.17?
same issue here
@kaili-yang Create a new issue following its instructions.
It worked for me by using the code !pip install pandas==1.3.5
and t hen restarting the kernel.
Just upgraded to yfinance-0.1.69 and pandas-1.4 you will likely hit this issue. The code is trivial and used to work fine. Any suggestions?
python-3.9.10 windows 10