Skip to content

Commit

Permalink
Fix: datetime.datetime.utcnow() is deprecated ...
Browse files Browse the repository at this point in the history
Python 3.12 deprecates datetime.datetime.utcnow().
Instead of switching to datetime.datetime.now(datetime.UTC), which won't work in Python 3.11,
just switch to Pandas.utcnow().
  • Loading branch information
ValueRaider committed May 2, 2024
1 parent 84ba6d7 commit c5aead9
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(end, unit='s')
if quotes.index[quotes.shape[0] - 1] >= endDt:
quotes = quotes.iloc[0:quotes.shape[0] - 1]
except Exception:
Expand Down

0 comments on commit c5aead9

Please sign in to comment.