Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix times appearing in output from yf.download(ignore_tz=True) #2109

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading