yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

Patch keyError in #2027

Open aleksfasting opened this issue 1 year ago • 3 comments

Solves ´KeyError´ occurrence in #2027.

Adds Try/Except statement to find keyerror and return to old code if the keyerror is triggered.

aleksfasting avatar Aug 19 '24 19:08 aleksfasting

That's not the solution. Look at the metadata.

ValueRaider avatar Aug 19 '24 19:08 ValueRaider

The same information as in the original PR, #2026, can be fetched from the 'currentTradingPeriod' key in the metadata. The metadata from the code that triggered the KeyError,

dat = yf.Ticker('0001.HK')
dat.history(start=1719763200, end=1720540800, interval='30m', prepost=True)

will have the same format as most other stocks for this key.

I don't know if Yahoo Finance may give differently formated metadata for the ´'currentTradingPeriod'´ key.

aleksfasting avatar Aug 20 '24 01:08 aleksfasting

Just add 2 unit tests: one with prepost=False, other with True. Then rebase to dev branch #1084

ValueRaider avatar Aug 20 '24 09:08 ValueRaider