Skip to content

Commit

Permalink
Merge pull request #1981 from ranaroussi/fix/pandas-warnings
Browse files Browse the repository at this point in the history
Prices: fix some Pandas deprecation warnings
  • Loading branch information
ValueRaider authored Jul 15, 2024
2 parents b0e9e91 + 742cc85 commit 96279b9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions yfinance/scrapers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def history(self, period="1mo", interval="1d",
# 2) fix weired bug with Yahoo! - returning 60m for 30m bars
if interval.lower() == "30m":
logger.debug(f'{self.ticker}: resampling 30m OHLC from 15m')
quotes2 = quotes.resample('30T')
quotes2 = quotes.resample('30min')
quotes = pd.DataFrame(index=quotes2.last().index, data={
'Open': quotes2['Open'].first(),
'High': quotes2['High'].max(),
Expand Down Expand Up @@ -1029,6 +1029,7 @@ def _fix_zeroes(self, df, interval, tz_exchange, prepost):
f_zero_or_nan_ignore = np.isin(f_prices_bad.index.date, dts)
df2_reserve = df2[f_zero_or_nan_ignore]
df2 = df2[~f_zero_or_nan_ignore]
df2 = df2.copy()
f_prices_bad = (df2[price_cols] == 0.0) | df2[price_cols].isna()

f_change = df2["High"].to_numpy() != df2["Low"].to_numpy()
Expand Down Expand Up @@ -1598,9 +1599,9 @@ def map_signals_to_ranges(f, f_up, f_down):
f_open_and_closed_fixed = f_open_fixed & f_close_fixed
f_open_xor_closed_fixed = np.logical_xor(f_open_fixed, f_close_fixed)
if f_open_and_closed_fixed.any():
df2.loc[f_open_and_closed_fixed, "Volume"] *= m_rcp
df2.loc[f_open_and_closed_fixed, "Volume"] = (df2.loc[f_open_and_closed_fixed, "Volume"] * m_rcp).round().astype('int')
if f_open_xor_closed_fixed.any():
df2.loc[f_open_xor_closed_fixed, "Volume"] *= 0.5 * m_rcp
df2.loc[f_open_xor_closed_fixed, "Volume"] = (df2.loc[f_open_xor_closed_fixed, "Volume"] * 0.5 * m_rcp).round().astype('int')

df2.loc[f_corrected, 'Repaired?'] = True

Expand Down Expand Up @@ -1653,7 +1654,8 @@ def map_signals_to_ranges(f, f_up, f_down):
for c in ['Open', 'High', 'Low', 'Close', 'Adj Close']:
df2.iloc[r[0]:r[1], df2.columns.get_loc(c)] *= m
if correct_volume:
df2.iloc[r[0]:r[1], df2.columns.get_loc("Volume")] *= m_rcp
col_loc = df2.columns.get_loc("Volume")
df2.iloc[r[0]:r[1], col_loc] = (df2.iloc[r[0]:r[1], col_loc] * m_rcp).round().astype('int')
df2.iloc[r[0]:r[1], df2.columns.get_loc('Repaired?')] = True
if r[0] == r[1] - 1:
if interday:
Expand Down

0 comments on commit 96279b9

Please sign in to comment.