Remove export to file now that we are returning a dataframe. Always return a dataframe even if empty. Update tests to reflect removed function arguments. Update documentation as well.

This commit is contained in:
Joseph Walker
2023-02-10 13:21:28 -05:00
parent e31c206b6a
commit a11810ac74
5 changed files with 11 additions and 31 deletions

View File

@@ -242,10 +242,6 @@ class StocksController(StockBaseController):
exchange_country=exchange,
all_exchanges=ns_parser.all_exchanges,
limit=ns_parser.limit,
export=ns_parser.export,
sheet_name=" ".join(ns_parser.sheet_name)
if ns_parser.sheet_name
else None,
)
@log_start_end(log=logger)

View File

@@ -27,7 +27,6 @@ from scipy import stats
from openbb_terminal import config_terminal as cfg
from openbb_terminal.helper_funcs import (
export_data,
lambda_long_number_format_y_axis,
plot_autoscale,
print_rich_table,
@@ -106,9 +105,7 @@ def search(
exchange_country: str = "",
all_exchanges: bool = False,
limit: int = 0,
export: str = "",
sheet_name: Optional[str] = "",
) -> Optional[pd.DataFrame]:
) -> pd.DataFrame:
"""Search selected query for tickers.
Parameters
@@ -127,13 +124,12 @@ def search(
Whether to search all exchanges, without this option only the United States market is searched
limit : int
The limit of companies shown.
export : str
Export data
Returns
-------
df: Optional[pd.DataFrame]
Dataframe of search results if any results are found
df: pd.DataFrame
Dataframe of search results.
Empty Dataframe if none are found.
Examples
--------
@@ -162,10 +158,10 @@ def search(
console.print(
"[red]No companies were found that match the given criteria.[/red]\n"
)
return
return pd.DataFrame()
if not data:
console.print("No companies found.\n")
return
return pd.DataFrame()
if query:
d = fd.search_products(
@@ -185,7 +181,7 @@ def search(
if not d:
console.print("No companies found.\n")
return
return pd.DataFrame()
df = pd.DataFrame.from_dict(d).T[
["long_name", "short_name", "country", "sector", "industry", "exchange"]
@@ -229,13 +225,6 @@ def search(
headers=["Name", "Country", "Sector", "Industry", "Exchange"],
title=title,
)
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"search",
df,
sheet_name,
)
return df

View File

@@ -263,8 +263,6 @@ def test_call_func_expect_queue(expected_queue, func, queue):
industry="",
all_exchanges=False,
exchange_country="",
export="csv",
sheet_name=None,
),
),
(

View File

@@ -50,7 +50,6 @@ def test_search(mocker, use_tab):
exchange_country="",
all_exchanges=False,
limit=5,
export="",
)

View File

@@ -10,7 +10,7 @@ Search selected query for tickers.
Source Code: [[link](https://github.com/OpenBB-finance/OpenBBTerminal/tree/main/openbb_terminal/stocks/stocks_helper.py#L98)]
```python
openbb.stocks.search(query: str = "", country: str = "", sector: str = "", industry: str = "", exchange_country: str = "", limit: int = 0, export: str = "", sheet_name: Optional[str] = "")
openbb.stocks.search(query: str = "", country: str = "", sector: str = "", industry: str = "", exchange_country: str = "", limit: int = 0)
```
---
@@ -25,16 +25,14 @@ openbb.stocks.search(query: str = "", country: str = "", sector: str = "", indus
| industry | str | Search by industry to find stocks matching the criteria | | True |
| exchange_country | str | Search by exchange country to find stock matching | | True |
| limit | int | The limit of companies shown. | 0 | True |
| export | str | Export data | | True |
| sheet_name | str | Sheet Name | | True |
---
## Returns
| Type | Description |
|------------------------|---------------------------------|
| Optional[pd.DataFrame] | Search results if any are found |
| Type | Description |
|--------------|----------------|
| pd.DataFrame | Search results |
---