ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

hh::mm::ss and timezone showing up as part of Date #2106

Closed satoshi closed 9 hours ago

satoshi commented 2 weeks ago

Describe bug

Until 0.2.44, the Date column only contained the date:

[*********************100%***********************]  1 of 1 completed
                 Open       High        Low      Close  Adj Close   Volume
Date
2011-01-04  158280.00  162700.00  158280.00  158460.00  158460.00       56
2011-01-05  160100.00  160200.00  154360.00  155100.00  155100.00       37
2011-01-06  154880.00  157360.00  153740.00  155760.00  155760.00       42
2011-01-07  154480.00  160020.00  152360.00  156080.00  156080.00       22
2011-01-10  159280.00  161740.00  155520.00  155760.00  155760.00       35

However, 0.2.48 produces the following (notice the 00:00:00+00:00)

[*********************100%***********************]  1 of 1 completed
Price                      Adj Close      Close       High        Low       Open   Volume
Ticker                          VIXY       VIXY       VIXY       VIXY       VIXY     VIXY
Date
2011-01-04 00:00:00+00:00  158460.00  158460.00  162700.00  158280.00  158280.00       56
2011-01-05 00:00:00+00:00  155100.00  155100.00  160200.00  154360.00  160100.00       37
2011-01-06 00:00:00+00:00  155760.00  155760.00  157360.00  153740.00  154880.00       42
2011-01-07 00:00:00+00:00  156080.00  156080.00  160020.00  152360.00  154480.00       22
2011-01-10 00:00:00+00:00  155760.00  155760.00  161740.00  155520.00  159280.00       35
...                              ...        ...        ...        ...        ...      ...
2024-10-25 00:00:00+00:00      13.63      13.63      13.66      12.77      12.90  5206400
2024-10-28 00:00:00+00:00      13.01      13.01      13.17      12.83      13.07  4404900
2024-10-29 00:00:00+00:00      12.94      12.94      13.14      12.76      13.06  2663000
2024-10-30 00:00:00+00:00      13.24      13.24      13.29      12.85      13.06  3199200
2024-10-31 00:00:00+00:00      14.30      14.30      14.31      13.59      13.60  6001400

Any way to get rid of the 00:00:00+00:00? This makes it really difficult to key table operations off of the Date.

Simple code that reproduces your problem

import yfinance as yf

vixy = yf.download('VIXY')
print(vixy)

Debug log

DEBUG    Entering download()
DEBUG     Disabling multithreading because DEBUG logging enabled
DEBUG     Entering history()
DEBUG      Entering history()
DEBUG       VIXY: Yahoo GET parameters: {'period1': '1925-11-26 09:50:04-05:00', 'period2': '2024-11-01 10:50:04-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG       Entering get()
DEBUG        Entering _make_request()
DEBUG         url=https://query2.finance.yahoo.com/v8/finance/chart/VIXY
DEBUG         params={'period1': -1391591396, 'period2': 1730472604, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG         Entering _get_cookie_and_crumb()
DEBUG          cookie_mode = 'basic'
DEBUG          Entering _get_cookie_and_crumb_basic()
DEBUG           loaded persistent cookie
DEBUG           reusing cookie
DEBUG           crumb = 'RRaVJQIQUML'
DEBUG          Exiting _get_cookie_and_crumb_basic()
DEBUG         Exiting _get_cookie_and_crumb()
DEBUG         response code=200
DEBUG        Exiting _make_request()
DEBUG       Exiting get()
DEBUG       VIXY: yfinance received OHLC data: 2011-01-04 14:30:00 -> 2024-10-31 13:30:00
DEBUG       VIXY: OHLC after cleaning: 2011-01-04 09:30:00-05:00 -> 2024-10-31 09:30:00-04:00
DEBUG       VIXY: OHLC after combining events: 2011-01-04 00:00:00-05:00 -> 2024-10-31 00:00:00-04:00
DEBUG       VIXY: yfinance returning OHLC: 2011-01-04 00:00:00-05:00 -> 2024-10-31 00:00:00-04:00
DEBUG      Exiting history()
DEBUG     Exiting history()
DEBUG    Exiting download()

Bad data proof

No response

yfinance version

0.2.44 and 0.2.48

Python version

No response

Operating system

No response

ValueRaider commented 2 weeks ago

Cause is https://github.com/ranaroussi/yfinance/releases/tag/0.2.47

satoshi commented 2 weeks ago

Cause is https://github.com/ranaroussi/yfinance/releases/tag/0.2.47

Which part? I specified multi_level_index=False but the 00:00:00+00:00 business remained (the Ticker row went away):

import yfinance as yf

vixy = yf.download('VIXY', multi_level_index=False)

print(vixy)

[*********************100%***********************]  1 of 1 completed
                           Adj Close      Close         High        Low       Open   Volume
Date                                                                                       
2011-01-04 00:00:00+00:00  158460.00  158460.00  162700.0000  158280.00  158280.00       56
2011-01-05 00:00:00+00:00  155100.00  155100.00  160200.0000  154360.00  160100.00       37
2011-01-06 00:00:00+00:00  155760.00  155760.00  157360.0000  153740.00  154880.00       42
2011-01-07 00:00:00+00:00  156080.00  156080.00  160020.0000  152360.00  154480.00       22
2011-01-10 00:00:00+00:00  155760.00  155760.00  161740.0000  155520.00  159280.00       35
tjay1275 commented 2 weeks ago

Satoshi, Would you mind telling me where you got the info to add multi_level_index=false? This one help me solve the issue with my python code.

satoshi commented 2 weeks ago

Satoshi, Would you mind telling me where you got the info to add multi_level_index=false? This one help me solve the issue with my python code.

I read this issue: https://github.com/ranaroussi/yfinance/issues/2100#issuecomment-2438442056, and it is something you can specify when calling download: https://github.com/ranaroussi/yfinance/blob/main/yfinance/multi.py#L41

ValueRaider commented 2 weeks ago

Cause is https://github.com/ranaroussi/yfinance/releases/tag/0.2.47

I was wrong, cause is 0.2.45, and I know the fix - it's not multi_level_index

ValueRaider commented 2 weeks ago

Fixed in dev branch

satoshi commented 2 weeks ago

Fixed in dev branch

Great, thank you very much!