summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormontezdesousa <79287829+montezdesousa@users.noreply.github.com>2024-03-06 17:40:57 +0000
committerGitHub <noreply@github.com>2024-03-06 17:40:57 +0000
commit76556dfd28137c6ed0fd25ac883d8359edef7c37 (patch)
treefefbf94822383bbd138ebd010df0b8468f22ca81
parent65ce66e033f6e1474c5684fe9341e32492e605a7 (diff)
[Bug fix] - Fix integration tests (#6170)
* fix integration tests * rebuild * unittest
-rw-r--r--openbb_platform/core/openbb_core/api/rest_api.py2
-rw-r--r--openbb_platform/extensions/equity/integration/test_equity_api.py2
-rw-r--r--openbb_platform/extensions/equity/integration/test_equity_python.py10
-rw-r--r--openbb_platform/extensions/quantitative/integration/test_quantitative_api.py18
-rw-r--r--openbb_platform/extensions/quantitative/openbb_quantitative/stats/stats_router.py11
-rw-r--r--openbb_platform/extensions/technical/openbb_technical/technical_router.py2
-rw-r--r--openbb_platform/openbb/package/equity_fundamental.py8
-rw-r--r--openbb_platform/providers/intrinio/openbb_intrinio/models/equity_historical.py11
-rw-r--r--openbb_platform/providers/nasdaq/openbb_nasdaq/models/economic_calendar.py12
9 files changed, 45 insertions, 31 deletions
diff --git a/openbb_platform/core/openbb_core/api/rest_api.py b/openbb_platform/core/openbb_core/api/rest_api.py
index 8705b8fa35b..7c9e0f1488e 100644
--- a/openbb_platform/core/openbb_core/api/rest_api.py
+++ b/openbb_platform/core/openbb_core/api/rest_api.py
@@ -88,6 +88,7 @@ AppLoader.from_routers(
@app.exception_handler(Exception)
async def api_exception_handler(_: Request, exc: Exception):
"""Exception handler for all other exceptions."""
+ logger.error(exc)
return JSONResponse(
status_code=404,
content={
@@ -100,6 +101,7 @@ async def api_exception_handler(_: Request, exc: Exception):
@app.exception_handler(OpenBBError)
async def openbb_exception_handler(_: Request, exc: OpenBBError):
"""Exception handler for OpenBB errors."""
+ logger.error(exc.original)
openbb_error = exc.original
status_code = 400 if "No results" in str(openbb_error) else 500
return JSONResponse(
diff --git a/openbb_platform/extensions/equity/integration/test_equity_api.py b/openbb_platform/extensions/equity/integration/test_equity_api.py
index 401ae64cd8a..465513c42b0 100644
--- a/openbb_platform/extensions/equity/integration/test_equity_api.py
+++ b/openbb_platform/extensions/equity/integration/test_equity_api.py
@@ -1675,7 +1675,7 @@ def test_equity_darkpool_otc(params, headers):
"params",
[
({"provider": "fmp", "market": "euronext"}),
- ({"provider": "polygon"}), # premium endpoint
+ # ({"provider": "polygon"}), # premium endpoint
],
)
@pytest.mark.integration
diff --git a/openbb_platform/extensions/equity/integration/test_equity_python.py b/openbb_platform/extensions/equity/integration/test_equity_python.py
index 6c1150d24f5..5dcef760320 100644
--- a/openbb_platform/extensions/equity/integration/test_equity_python.py
+++ b/openbb_platform/extensions/equity/integration/test_equity_python.py
@@ -1,6 +1,6 @@
"""Python interface integration tests for the equity extension."""
-from datetime import time
+from datetime import date, time, timedelta
import pytest
from extensions.tests.conftest import parametrize
@@ -767,8 +767,6 @@ def test_equity_fundamental_revenue_per_segment(params, obb):
"symbol": "IBM:US",
"start_date": "2023-09-30",
"end_date": "2023-12-31",
- "limit": None,
- "form_type": None,
}
),
],
@@ -878,8 +876,8 @@ def test_equity_compare_groups(params, obb):
{
"provider": "cboe",
"symbol": "AAPL",
- "start_date": "2024-02-19",
- "end_date": "2024-02-20",
+ "start_date": (date.today() - timedelta(days=1)).strftime("%Y-%m-%d"),
+ "end_date": date.today().strftime("%Y-%m-%d"),
"interval": "1m",
"use_cache": False,
}
@@ -1572,7 +1570,7 @@ def test_equity_darkpool_otc(params, obb):
"params",
[
({"provider": "fmp", "market": "euronext"}),
- ({"provider": "polygon"}), # premium endpoint
+ # ({"provider": "polygon"}), # premium endpoint
],
)
@pytest.mark.integration
diff --git a/openbb_platform/extensions/quantitative/integration/test_quantitative_api.py b/openbb_platform/extensions/quantitative/integration/test_quantitative_api.py
index 10e9432d1f8..ecb4960c4d4 100644
--- a/openbb_platform/extensions/quantitative/integration/test_quantitative_api.py
+++ b/openbb_platform/extensions/quantitative/integration/test_quantitative_api.py
@@ -26,9 +26,11 @@ def get_headers():
return data["headers"]
-def request_data(menu: str, symbol: str, provider: str):
+def request_data(
+ menu: str, symbol: str, provider: str, start_date: str = "", end_date: str = ""
+):
"""Randomly pick a symbol and a provider and get data from the selected menu."""
- url = f"http://0.0.0.0:8000/api/v1/{menu}/price/historical?symbol={symbol}&provider={provider}"
+ url = f"http://0.0.0.0:8000/api/v1/{menu}/price/historical?symbol={symbol}&provider={provider}&start_date={start_date}&end_date={end_date}"
result = requests.get(url, headers=get_headers(), timeout=10)
return result.json()["results"]
@@ -40,7 +42,13 @@ def get_stocks_data():
symbol = random.choice(["AAPL", "NVDA", "MSFT", "TSLA", "AMZN", "V"]) # noqa: S311
provider = random.choice(["fmp", "polygon", "yfinance"]) # noqa: S311
- data["stocks_data"] = request_data("equity", symbol=symbol, provider=provider)
+ data["stocks_data"] = request_data(
+ menu="equity",
+ symbol=symbol,
+ provider=provider,
+ start_date="2023-01-01",
+ end_date="2023-12-31",
+ )
return data["stocks_data"]
@@ -56,6 +64,8 @@ def get_crypto_data():
menu="crypto",
symbol=symbol,
provider=provider,
+ start_date="2023-01-01",
+ end_date="2023-12-31",
)
return data["crypto_data"]
@@ -244,7 +254,7 @@ def test_quantitative_performance_sharpe_ratio(params, data_type):
"data": "",
"target": "close",
"target_return": "0.5",
- "window": "275",
+ "window": "150",
"adjusted": "true",
"index": "date",
},
diff --git a/openbb_platform/extensions/quantitative/openbb_quantitative/stats/stats_router.py b/openbb_platform/extensions/quantitative/openbb_quantitative/stats/stats_router.py
index deff80471b1..56ab1017ecf 100644
--- a/openbb_platform/extensions/quantitative/openbb_quantitative/stats/stats_router.py
+++ b/openbb_platform/extensions/quantitative/openbb_quantitative/stats/stats_router.py
@@ -144,7 +144,7 @@ def stdev(data: List[Data], target: str) -> OBBject[List[Data]]:
'obb.quantitative.stats.kurtosis(data=returns, target="close")',
],
)
-def kurtosis(data: List[Data], target) -> OBBject[List[Data]]:
+def kurtosis(data: List[Data], target: str) -> OBBject[List[Data]]:
"""
Calculate the rolling kurtosis of a target column.
@@ -154,10 +154,11 @@ def kurtosis(data: List[Data], target) -> OBBject[List[Data]]:
This function helps in assessing the risk of outliers in financial returns or other time series data.
Parameters
- data: List[Data]
- The time series data as a list of data points.
- target: str
- The name of the column for which to calculate kurtosis.
+ ----------
+ data: List[Data]
+ The time series data as a list of data points.
+ target: str
+ The name of the column for which to calculate kurtosis.
Returns
------
diff --git a/openbb_platform/extensions/technical/openbb_technical/technical_router.py b/openbb_platform/extensions/technical/openbb_technical/technical_router.py
index 60b27220b95..245ac33c799 100644
--- a/openbb_platform/extensions/technical/openbb_technical/technical_router.py
+++ b/openbb_platform/extensions/technical/openbb_technical/technical_router.py
@@ -623,6 +623,8 @@ def vwap(
The calculated data.
"""
df = basemodel_to_df(data, index=index)
+ if index == "date":
+ df.index = pd.to_datetime(df.index)
df_target = get_target_columns(df, ["high", "low", "close", "volume"])
df_vwap = pd.DataFrame(df_target.ta.vwap(anchor=anchor, offset=offset).dropna())
diff --git a/openbb_platform/openbb/package/equity_fundamental.py b/openbb_platform/openbb/package/equity_fundamental.py
index b62691b6a2d..9ad938292d9 100644
--- a/openbb_platform/openbb/package/equity_fundamental.py
+++ b/openbb_platform/openbb/package/equity_fundamental.py
@@ -708,6 +708,10 @@ class ROUTER_equity_fundamental(Container):
Link to the filing. (provider: fmp)
final_link : Optional[str]
Link to the filing document. (provider: fmp)
+ net_income_continuing_operations : Optional[float]
+ Net Income (Continuing Operations) (provider: intrinio)
+ net_income_discontinued_operations : Optional[float]
+ Net Income (Discontinued Operations) (provider: intrinio)
provision_for_loan_losses : Optional[float]
Provision for Loan Losses (provider: intrinio)
provision_for_credit_losses : Optional[float]
@@ -726,10 +730,6 @@ class ROUTER_equity_fundamental(Container):
Net Cash from Continuing Operating Activities (provider: intrinio)
net_cash_from_discontinued_operating_activities : Optional[float]
Net Cash from Discontinued Operating Activities (provider: intrinio)
- net_income_continuing_operations : Optional[float]
- Net Income (Continuing Operations) (provider: intrinio)
- net_income_discontinued_operations : Optional[float]
- Net Income (Discontinued Operations) (provider: intrinio)
divestitures : Optional[float]
Divestitures (provider: intrinio)
sale_of_property_plant_and_equipment : Optional[float]
diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/equity_historical.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/equity_historical.py
index d06785ac7b0..d6be9d79f6e 100644
--- a/openbb_platform/providers/intrinio/openbb_intrinio/models/equity_historical.py
+++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/equity_historical.py
@@ -230,7 +230,10 @@ class IntrinioEquityHistoricalFetcher(
**kwargs: Any,
) -> List[IntrinioEquityHistoricalData]:
"""Return the transformed data."""
- return [
- IntrinioEquityHistoricalData.model_validate(d)
- for d in sorted(data, key=lambda x: x["date"], reverse=False)
- ]
+ try:
+ sorted_data = sorted(
+ data, key=lambda x: x.get("date") or x.get("time"), reverse=False
+ )
+ except Exception:
+ sorted_data = data
+ return [IntrinioEquityHistoricalData.model_validate(d) for d in sorted_data]
diff --git a/openbb_platform/providers/nasdaq/openbb_nasdaq/models/economic_calendar.py b/openbb_platform/providers/nasdaq/openbb_nasdaq/models/economic_calendar.py
index 7baae29800e..3970a0b091b 100644
--- a/openbb_platform/providers/nasdaq/openbb_nasdaq/models/economic_calendar.py
+++ b/openbb_platform/providers/nasdaq/openbb_nasdaq/models/economic_calendar.py
@@ -4,7 +4,7 @@ import html
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from itertools import repeat
-from typing import Any, Dict, List, Optional, Set, Union
+from typing import Any, Dict, List, Optional
import requests
from openbb_core.provider.abstract.fetcher import Fetcher
@@ -24,18 +24,16 @@ class NasdaqEconomicCalendarQueryParams(EconomicCalendarQueryParams):
__json_schema_extra__ = {"country": ["multiple_items_allowed"]}
- country: Optional[Union[str, List[str]]] = Field(
+ country: Optional[str] = Field(
default=None,
description="Country of the event",
)
@field_validator("country", mode="before", check_fields=False)
@classmethod
- def validate_country(cls, v: Union[str, List[str], Set[str]]):
- """Validate the country input."""
- if isinstance(v, str):
- return v.lower().replace(" ", "_")
- return ",".join([country.lower().replace(" ", "_") for country in list(v)])
+ def validate_country(cls, c: str): # pylint: disable=E0213
+ """Validate country."""
+ return ",".join([v.lower() for v in c.replace(" ", "_").split(",")])
class NasdaqEconomicCalendarData(EconomicCalendarData):