Skip to content

Commit

Permalink
Fix: datetime.datetime.utcnow() is deprecated ...
Browse files Browse the repository at this point in the history
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  • Loading branch information
ValueRaider committed Apr 28, 2024
1 parent 84ba6d7 commit 342499a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_duplicatingHourly(self):
dat = yf.Ticker(tkr, session=self.session)
tz = dat._get_ticker_tz(proxy=None, timeout=None)

dt_utc = _tz.timezone("UTC").localize(_dt.datetime.utcnow())
dt_utc = _dt.datetime.now(_dt.UTC)
dt = dt_utc.astimezone(_tz.timezone(tz))
start_d = dt.date() - _dt.timedelta(days=7)
df = dat.history(start=start_d, interval="1h")
Expand All @@ -82,7 +82,7 @@ def test_duplicatingDaily(self):
dat = yf.Ticker(tkr, session=self.session)
tz = dat._get_ticker_tz(proxy=None, timeout=None)

dt_utc = _tz.timezone("UTC").localize(_dt.datetime.utcnow())
dt_utc = _dt.datetime.now(_dt.UTC)
dt = dt_utc.astimezone(_tz.timezone(tz))
if dt.time() < _dt.time(17, 0):
continue
Expand Down
2 changes: 1 addition & 1 deletion yfinance/scrapers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def history(self, period="1mo", interval="1d",
quotes = utils.parse_quotes(data["chart"]["result"][0])
# Yahoo bug fix - it often appends latest price even if after end date
if end and not quotes.empty:
endDt = pd.to_datetime(_datetime.datetime.utcfromtimestamp(end))
endDt = pd.to_datetime(_datetime.datetime.fromtimestamp(end, _datetime.UTC)).tz_localize(None)
if quotes.index[quotes.shape[0] - 1] >= endDt:
quotes = quotes.iloc[0:quotes.shape[0] - 1]
except Exception:
Expand Down

0 comments on commit 342499a

Please sign in to comment.