Skip to content

Commit

Permalink
Tests small fixes + fix another Pandas warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Jul 15, 2024
1 parent 96279b9 commit 0681a77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/test_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def test_repair_bad_stock_splits(self):

fp = os.path.join(_dp, "data", tkr.replace('.','-')+'-'+interval+"-bad-stock-split-fixed.csv")
correct_df = _pd.read_csv(fp, index_col="Date")
correct_df.index = _pd.to_datetime(correct_df.index)
correct_df.index = _pd.to_datetime(correct_df.index, utc=True)

repaired_df = repaired_df.sort_index()
correct_df = correct_df.sort_index()
Expand Down
21 changes: 0 additions & 21 deletions tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
("recommendations", Union[pd.DataFrame, dict]),
("recommendations_summary", Union[pd.DataFrame, dict]),
("upgrades_downgrades", Union[pd.DataFrame, dict]),
("earnings", pd.DataFrame),
("quarterly_earnings", pd.DataFrame),
("quarterly_cashflow", pd.DataFrame),
("cashflow", pd.DataFrame),
("quarterly_balance_sheet", pd.DataFrame),
Expand Down Expand Up @@ -114,9 +112,6 @@ def test_badTicker(self):
for attribute_name, attribute_type in ticker_attributes:
assert_attribute_type(self, dat, attribute_name, attribute_type)

with self.assertRaises(YFNotImplementedError):
assert isinstance(dat.earnings, pd.Series)
assert dat.earnings.empty
assert isinstance(dat.dividends, pd.Series)
assert dat.dividends.empty
assert isinstance(dat.splits, pd.Series)
Expand Down Expand Up @@ -309,22 +304,6 @@ def test_earnings_dates_with_limit(self):

# Below will fail because not ported to Yahoo API

# def test_earnings(self):
# data = self.ticker.earnings
# self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
# self.assertFalse(data.empty, "data is empty")

# data_cached = self.ticker.earnings
# self.assertIs(data, data_cached, "data not cached")

# def test_quarterly_earnings(self):
# data = self.ticker.quarterly_earnings
# self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
# self.assertFalse(data.empty, "data is empty")

# data_cached = self.ticker.quarterly_earnings
# self.assertIs(data, data_cached, "data not cached")

# def test_earnings_forecasts(self):
# data = self.ticker.earnings_forecasts
# self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
Expand Down
6 changes: 5 additions & 1 deletion yfinance/scrapers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,11 @@ def _fix_bad_stock_splits(self, df, interval, tz_exchange):
if cutoff_idx == df.shape[0]-1:
df = df_pre_split_repaired
else:
df = pd.concat([df_pre_split_repaired.sort_index(), df.iloc[cutoff_idx+1:]])
df_post_cutoff = df.iloc[cutoff_idx+1:]
if df_post_cutoff.empty:
df = df_pre_split_repaired.sort_index()
else:
df = pd.concat([df_pre_split_repaired.sort_index(), df_post_cutoff])
return df

@utils.log_indent_decorator
Expand Down

0 comments on commit 0681a77

Please sign in to comment.