Skip to content

Commit

Permalink
Merge pull request #1779 from VishnuAkundi/invalid_symbol_date_fix
Browse files Browse the repository at this point in the history
Fix for Key Error Issue on Date column when one of the symbols is no longer valid (delisted/not available)
  • Loading branch information
ValueRaider authored Dec 12, 2023
2 parents f08fe83 + 4a5616d commit 53c2948
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def test_download(self):

df_tkrs = df.columns.levels[1]
self.assertEqual(sorted(tkrs), sorted(df_tkrs))

def test_download_with_invalid_ticker(self):
#Checks if using an invalid symbol gives the same output as not using an invalid symbol in combination with a valid symbol (AAPL)
#Checks to make sure that invalid symbol handling for the date column is the same as the base case (no invalid symbols)

invalid_tkrs = ["AAPL", "ATVI"] #AAPL exists and ATVI does not exist
valid_tkrs = ["AAPL", "INTC"] #AAPL and INTC both exist

data_invalid_sym = yf.download(invalid_tkrs, start='2023-11-16', end='2023-11-17')
data_valid_sym = yf.download(valid_tkrs, start='2023-11-16', end='2023-11-17')

self.assertEqual(data_invalid_sym['Close']['AAPL']['2023-11-16'],data_valid_sym['Close']['AAPL']['2023-11-16'])

def test_duplicatingHourly(self):
tkrs = ["IMP.JO", "BHG.JO", "SSW.JO", "BP.L", "INTC"]
Expand Down
2 changes: 1 addition & 1 deletion yfinance/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def download(tickers, start=None, end=None, actions=False, threads=True, ignore_
_realign_dfs()
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
keys=shared._DFS.keys())

data.index = _pd.to_datetime(data.index)
# switch names back to isins if applicable
data.rename(columns=shared._ISINS, inplace=True)

Expand Down

0 comments on commit 53c2948

Please sign in to comment.