Skip to content

Commit

Permalink
Merge branch 'dev' into config
Browse files Browse the repository at this point in the history
  • Loading branch information
R5dan authored Jan 7, 2025
2 parents 57ff9aa + ffa697c commit 724509d
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 218 deletions.
5 changes: 4 additions & 1 deletion doc/source/reference/examples/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
quotes = yf.Search("AAPL", max_results=10).quotes

# get list of news
news = yf.Search("Google", news_count=10).news
news = yf.Search("Google", news_count=10).news

# get list of related research
research = yf.Search("apple", include_research=True).research
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ pytz>=2022.5
frozendict>=2.3.4
beautifulsoup4>=4.11.1
html5lib>=1.1
peewee>=3.16.2
peewee>=3.16.2
requests_cache>=1.0
requests_ratelimiter>=0.3.1
scipy>=1.6.3
25 changes: 18 additions & 7 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@


class TestSearch(unittest.TestCase):
def test_valid_query(self):
search = yf.Search(query="AAPL", max_results=5, news_count=3)

self.assertEqual(len(search.quotes), 5)
self.assertEqual(len(search.news), 3)
self.assertIn("AAPL", search.quotes[0]['symbol'])

def test_invalid_query(self):
search = yf.Search(query="XYZXYZ")

self.assertEqual(len(search.quotes), 0)
self.assertEqual(len(search.news), 0)
self.assertEqual(len(search.lists), 0)
self.assertEqual(len(search.nav), 0)
self.assertEqual(len(search.research), 0)

def test_empty_query(self):
search = yf.Search(query="")
Expand All @@ -29,3 +25,18 @@ def test_fuzzy_query(self):
# Check if the fuzzy search retrieves relevant results despite the typo
self.assertGreater(len(search.quotes), 0)
self.assertIn("AAPL", search.quotes[0]['symbol'])

def test_quotes(self):
search = yf.Search(query="AAPL", max_results=5)

self.assertEqual(len(search.quotes), 5)
self.assertIn("AAPL", search.quotes[0]['symbol'])

def test_news(self):
search = yf.Search(query="AAPL", news_count=3)

self.assertEqual(len(search.news), 3)

def test_research_reports(self):
search = yf.Search(query="AAPL", include_research=True)
self.assertEqual(len(search.research), 3)
26 changes: 13 additions & 13 deletions tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def test_upgrades_downgrades(self):
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")
self.assertTrue(len(data.columns) == 4, "data has wrong number of columns")
self.assertEqual(data.columns.values.tolist(), ['Firm', 'ToGrade', 'FromGrade', 'Action'], "data has wrong column names")
self.assertCountEqual(data.columns.values.tolist(), ['Firm', 'ToGrade', 'FromGrade', 'Action'], "data has wrong column names")
self.assertIsInstance(data.index, pd.DatetimeIndex, "data has wrong index type")

data_cached = self.ticker.upgrades_downgrades
Expand All @@ -771,7 +771,7 @@ def test_analyst_price_targets(self):
self.assertIsInstance(data, dict, "data has wrong type")

keys = {'current', 'low', 'high', 'mean', 'median'}
self.assertEqual(data.keys(), keys, "data has wrong keys")
self.assertCountEqual(data.keys(), keys, "data has wrong keys")

data_cached = self.ticker.analyst_price_targets
self.assertIs(data, data_cached, "data not cached")
Expand All @@ -782,10 +782,10 @@ def test_earnings_estimate(self):
self.assertFalse(data.empty, "data is empty")

columns = ['numberOfAnalysts', 'avg', 'low', 'high', 'yearAgoEps', 'growth']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")
self.assertCountEqual(data.columns.values.tolist(), columns, "data has wrong column names")

index = ['0q', '+1q', '0y', '+1y']
self.assertEqual(data.index.values.tolist(), index, "data has wrong row names")
self.assertCountEqual(data.index.values.tolist(), index, "data has wrong row names")

data_cached = self.ticker.earnings_estimate
self.assertIs(data, data_cached, "data not cached")
Expand All @@ -796,10 +796,10 @@ def test_revenue_estimate(self):
self.assertFalse(data.empty, "data is empty")

columns = ['numberOfAnalysts', 'avg', 'low', 'high', 'yearAgoRevenue', 'growth']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")
self.assertCountEqual(data.columns.values.tolist(), columns, "data has wrong column names")

index = ['0q', '+1q', '0y', '+1y']
self.assertEqual(data.index.values.tolist(), index, "data has wrong row names")
self.assertCountEqual(data.index.values.tolist(), index, "data has wrong row names")

data_cached = self.ticker.revenue_estimate
self.assertIs(data, data_cached, "data not cached")
Expand All @@ -810,7 +810,7 @@ def test_earnings_history(self):
self.assertFalse(data.empty, "data is empty")

columns = ['epsEstimate', 'epsActual', 'epsDifference', 'surprisePercent']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")
self.assertCountEqual(data.columns.values.tolist(), columns, "data has wrong column names")
self.assertIsInstance(data.index, pd.DatetimeIndex, "data has wrong index type")

data_cached = self.ticker.earnings_history
Expand All @@ -822,10 +822,10 @@ def test_eps_trend(self):
self.assertFalse(data.empty, "data is empty")

columns = ['current', '7daysAgo', '30daysAgo', '60daysAgo', '90daysAgo']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")
self.assertCountEqual(data.columns.values.tolist(), columns, "data has wrong column names")

index = ['0q', '+1q', '0y', '+1y']
self.assertEqual(data.index.values.tolist(), index, "data has wrong row names")
self.assertCountEqual(data.index.values.tolist(), index, "data has wrong row names")

data_cached = self.ticker.eps_trend
self.assertIs(data, data_cached, "data not cached")
Expand All @@ -835,11 +835,11 @@ def test_growth_estimates(self):
self.assertIsInstance(data, pd.DataFrame, "data has wrong type")
self.assertFalse(data.empty, "data is empty")

columns = ['stock', 'industry', 'sector', 'index']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")
columns = ['stockTrend', 'indexTrend']
self.assertCountEqual(data.columns.values.tolist(), columns, "data has wrong column names")

index = ['0q', '+1q', '0y', '+1y']
self.assertEqual(data.index.values.tolist(), index, "data has wrong row names")
index = ['0q', '+1q', '0y', '+1y', '+5y']
self.assertCountEqual(data.index.values.tolist(), index, "data has wrong row names")

data_cached = self.ticker.growth_estimates
self.assertIs(data, data_cached, "data not cached")
Expand Down
Loading

0 comments on commit 724509d

Please sign in to comment.