atreadw1492 / yahoo_fin

Scrape stock price history from new (Spring 2017) Yahoo Finance layout
MIT License
286 stars 125 forks source link

Python 3.8 warning in `tickers_sp500()` #54

Closed an4s closed 3 years ago

an4s commented 3 years ago

I have Python 3.8 installed on my system and see the following warning when using the tickers_sp500 function:

C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.

sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")

which can be traced back to the line of code below: https://github.com/atreadw1492/yahoo_fin/blob/730256155e7e97effa7df0f33a8ece03e56270da/yahoo_fin/stock_info.py#L130

The issue can be reproduced by running the following code:

PS > python
>>> from yahoo_fin import stock_info as si
>>> t = si.tickers_sp500()
C:\Python38\lib\site-packages\yahoo_fin\stock_info.py:130: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.

  sp500["Symbol"] = sp500["Symbol"].str.replace(".", "-")

Specs of my system: OS: Win10-64 bit Python: 3.8.2 yahoo_fin: 0.8.8

I believe changing replace(".", "-") to replace(".", "-", regex=True) in the line of code referenced above should take care of the warning (but I haven't tested it yet). See this issue referenced from the Pandas docs.

atreadw1492 commented 3 years ago

@an4s Thanks for the notification. I will push this update with the latest patch.