Skip to content

Commit

Permalink
Fix times appearing in output from yf.download(ignore_tz=True)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Nov 2, 2024
1 parent 0bc22f8 commit 4157b9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,24 @@ def test_history(self):
self.assertFalse(data.empty, "data is empty")

def test_download(self):
tomorrow = pd.Timestamp.now().date() + pd.Timedelta(days=1) # helps with caching
for t in [False, True]:
for i in [False, True]:
data = yf.download(self.symbols, threads=t, ignore_tz=i)
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")
for m in [False, True]:
for n in [1, 'all']:
symbols = self.symbols[0] if n == 1 else self.symbols
data = yf.download(symbols, end=tomorrow, session=self.session,
threads=t, ignore_tz=i, multi_level_index=m)
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")
if i:
self.assertIsNone(data.index.tz)
else:
self.assertIsNotNone(data.index.tz)
if (not m) and n == 1:
self.assertFalse(isinstance(data.columns, pd.MultiIndex))
else:
self.assertIsInstance(data.columns, pd.MultiIndex)

def test_no_expensive_calls_introduced(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion yfinance/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def download(tickers, start=None, end=None, actions=False, threads=True,
_realign_dfs()
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
keys=shared._DFS.keys(), names=['Ticker', 'Price'])
data.index = _pd.to_datetime(data.index, utc=True)
data.index = _pd.to_datetime(data.index, utc=not ignore_tz)
# switch names back to isins if applicable
data.rename(columns=shared._ISINS, inplace=True)

Expand Down

0 comments on commit 4157b9e

Please sign in to comment.