mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[BugFix] Fix empty docstring in data processing functions (#6206)
* update etf static file update reference.json with changes * data processing docstrings can be empty use self._write func to create reference.json file
This commit is contained in:
@@ -8,7 +8,7 @@ import shutil
|
||||
import sys
|
||||
from dataclasses import Field
|
||||
from inspect import Parameter, _empty, isclass, signature
|
||||
from json import dump, dumps, load
|
||||
from json import dumps, load
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
Any,
|
||||
@@ -189,11 +189,8 @@ class PackageBuilder:
|
||||
"""Save the reference.json file."""
|
||||
self.console.log("\nWriting reference file...")
|
||||
data = ReferenceGenerator.get_reference_data()
|
||||
file_path = self.directory / "assets" / "reference.json"
|
||||
# Dumping the reference dictionary as a JSON file
|
||||
self.console.log(str(file_path))
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
dump(data, f, indent=4)
|
||||
code = dumps(obj=data, indent=4)
|
||||
self._write(code=code, name="reference", extension="json", folder="assets")
|
||||
|
||||
def _run_linters(self):
|
||||
"""Run the linters."""
|
||||
@@ -1392,6 +1389,8 @@ class ReferenceGenerator:
|
||||
List of dictionaries containing the name,type, description, default
|
||||
and optionality of each parameter.
|
||||
"""
|
||||
parameters_list = []
|
||||
|
||||
# Define a regex pattern to match parameter blocks
|
||||
# This pattern looks for a parameter name followed by " : ", then captures the type and description
|
||||
pattern = re.compile(
|
||||
@@ -1401,33 +1400,31 @@ class ReferenceGenerator:
|
||||
# Find all matches in the docstring
|
||||
matches = pattern.finditer(docstring)
|
||||
|
||||
# Initialize an empty list to store parameter dictionaries
|
||||
parameters_list = []
|
||||
if matches:
|
||||
# Iterate over the matches to extract details
|
||||
for match in matches:
|
||||
# Extract named groups as a dictionary
|
||||
param_info = match.groupdict()
|
||||
|
||||
# Iterate over the matches to extract details
|
||||
for match in matches:
|
||||
# Extract named groups as a dictionary
|
||||
param_info = match.groupdict()
|
||||
# Determine if the parameter is optional
|
||||
is_optional = "Optional" in param_info["type"]
|
||||
|
||||
# Determine if the parameter is optional
|
||||
is_optional = "Optional" in param_info["type"]
|
||||
# If no default value is captured, set it to an empty string
|
||||
default_value = (
|
||||
param_info["default"] if param_info["default"] is not None else ""
|
||||
)
|
||||
|
||||
# If no default value is captured, set it to an empty string
|
||||
default_value = (
|
||||
param_info["default"] if param_info["default"] is not None else ""
|
||||
)
|
||||
# Create a new dictionary with fields in the desired order
|
||||
param_dict = {
|
||||
"name": param_info["name"],
|
||||
"type": param_info["type"],
|
||||
"description": param_info["description"],
|
||||
"default": default_value,
|
||||
"optional": is_optional,
|
||||
}
|
||||
|
||||
# Create a new dictionary with fields in the desired order
|
||||
param_dict = {
|
||||
"name": param_info["name"],
|
||||
"type": param_info["type"],
|
||||
"description": param_info["description"],
|
||||
"default": default_value,
|
||||
"optional": is_optional,
|
||||
}
|
||||
|
||||
# Append the dictionary to the list
|
||||
parameters_list.append(param_dict)
|
||||
# Append the dictionary to the list
|
||||
parameters_list.append(param_dict)
|
||||
|
||||
return parameters_list
|
||||
|
||||
@@ -1445,23 +1442,27 @@ class ReferenceGenerator:
|
||||
Dict[str, str]:
|
||||
Dictionary containing the name, type, description of the return value
|
||||
"""
|
||||
return_info = ""
|
||||
|
||||
# Define a regex pattern to match the Returns section
|
||||
# This pattern captures the model name inside "OBBject[]" and its description
|
||||
match = re.search(r"Returns\n\s*-------\n\s*([^\n]+)\n\s*([^\n]+)", docstring)
|
||||
return_type = match.group(1).strip() # type: ignore
|
||||
# Remove newlines and indentation from the description
|
||||
description = match.group(2).strip().replace("\n", "").replace(" ", "") # type: ignore
|
||||
# Adjust regex to correctly capture content inside brackets, including nested brackets
|
||||
content_inside_brackets = re.search(
|
||||
r"OBBject\[\s*((?:[^\[\]]|\[[^\[\]]*\])*)\s*\]", return_type
|
||||
)
|
||||
return_type_content = content_inside_brackets.group(1) # type: ignore
|
||||
|
||||
return_info = (
|
||||
f"OBBject\n"
|
||||
f"{create_indent(1)}results : {return_type_content}\n"
|
||||
f"{create_indent(2)}{description}"
|
||||
)
|
||||
if match:
|
||||
return_type = match.group(1).strip() # type: ignore
|
||||
# Remove newlines and indentation from the description
|
||||
description = match.group(2).strip().replace("\n", "").replace(" ", "") # type: ignore
|
||||
# Adjust regex to correctly capture content inside brackets, including nested brackets
|
||||
content_inside_brackets = re.search(
|
||||
r"OBBject\[\s*((?:[^\[\]]|\[[^\[\]]*\])*)\s*\]", return_type
|
||||
)
|
||||
return_type_content = content_inside_brackets.group(1) # type: ignore
|
||||
|
||||
return_info = (
|
||||
f"OBBject\n"
|
||||
f"{create_indent(1)}results : {return_type_content}\n"
|
||||
f"{create_indent(2)}{description}"
|
||||
)
|
||||
|
||||
return return_info
|
||||
|
||||
@@ -1557,21 +1558,18 @@ class ReferenceGenerator:
|
||||
# POST method router `description` attribute is unreliable as it may or
|
||||
# may not contain the "Parameters" and "Returns" sections. Hence, the
|
||||
# endpoint function docstring is used instead.
|
||||
description = route_func.__doc__.split("Parameters")[0].strip() # type: ignore
|
||||
docstring = getattr(route_func, "__doc__", "")
|
||||
description = docstring.split("Parameters")[0].strip()
|
||||
# Remove extra spaces in between the string
|
||||
reference[path]["description"] = re.sub(" +", " ", description)
|
||||
# Add endpoint parameters fields for POST methods
|
||||
reference[path]["parameters"][
|
||||
"standard"
|
||||
] = ReferenceGenerator.get_post_method_parameters_info(
|
||||
route_func.__doc__ # type: ignore
|
||||
reference[path]["parameters"]["standard"] = (
|
||||
ReferenceGenerator.get_post_method_parameters_info(docstring)
|
||||
)
|
||||
# Add endpoint returns data
|
||||
# Currently only OBBject object is returned
|
||||
reference[path]["returns"][
|
||||
"OBBject"
|
||||
] = cls.get_post_method_returns_info(
|
||||
route_func.__doc__ # type: ignore
|
||||
reference[path]["returns"]["OBBject"] = (
|
||||
cls.get_post_method_returns_info(docstring)
|
||||
)
|
||||
|
||||
return reference
|
||||
|
||||
25562
openbb_platform/openbb/assets/reference.json
vendored
25562
openbb_platform/openbb/assets/reference.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -896,6 +896,8 @@ class ROUTER_etf(Container):
|
||||
Investment style of the ETF. (provider: intrinio)
|
||||
derivatives_based : Optional[str]
|
||||
This field is populated if the ETF holds either listed or over-the-counter derivatives in its portfolio. (provider: intrinio)
|
||||
income_category : Optional[str]
|
||||
Identifies if an Exchange Traded Fund (ETF) falls into a category that is specifically designed to provide a high yield or income (provider: intrinio)
|
||||
other_asset_types : Optional[str]
|
||||
If 'asset_class' field is classified as 'Other Asset Types' this field captures the specific category of the underlying assets. (provider: intrinio)
|
||||
single_category_designation : Optional[str]
|
||||
@@ -994,6 +996,8 @@ class ROUTER_etf(Container):
|
||||
For ETFs where 'commodity_type' is 'Energy', this field provides detail on the type of energy exposure provided by the ETF. (provider: intrinio)
|
||||
agricultural_type : Optional[str]
|
||||
For ETFs where 'commodity_type' is 'Agricultural', this field provides detail on the type of agricultural exposure provided by the ETF. (provider: intrinio)
|
||||
livestock_type : Optional[str]
|
||||
For ETFs where 'commodity_type' is 'Livestock', this field provides detail on the type of livestock exposure provided by the ETF. (provider: intrinio)
|
||||
metal_type : Optional[str]
|
||||
For ETFs where 'commodity_type' is 'Gold & Metals', this field provides detail on the type of exposure provided by the ETF. (provider: intrinio)
|
||||
inverse_leveraged : Optional[str]
|
||||
@@ -1010,6 +1014,12 @@ class ROUTER_etf(Container):
|
||||
This field is populated if the ETF has an intended investment objective of holding dividend-oriented stocks as stated in the prospectus. (provider: intrinio)
|
||||
regular_dividend_payor_type : Optional[str]
|
||||
This field is populated if the ETF has a value of'Dividend - Regular Payors' in the 'dividend_type' field. (provider: intrinio)
|
||||
quant_strategies_type : Optional[str]
|
||||
This field is populated if the ETF has either an index-linked or active strategy that is based on a proprietary quantitative strategy. (provider: intrinio)
|
||||
other_quant_models : Optional[str]
|
||||
For ETFs where 'quant_strategies_type' is 'Other Quant Model', this field provides the name of the specific proprietary quant model used as the underlying strategy for the ETF. (provider: intrinio)
|
||||
hedge_fund_type : Optional[str]
|
||||
For ETFs where 'other_asset_types' is 'Hedge Fund Replication', this field provides detail on the type of hedge fund replication strategy. (provider: intrinio)
|
||||
excludes_financials : Optional[bool]
|
||||
For equity ETFs, identifies those ETFs where the underlying fund holdings will not hold financials stocks, based on the funds intended objective. (provider: intrinio)
|
||||
excludes_technology : Optional[bool]
|
||||
@@ -1042,14 +1052,6 @@ class ROUTER_etf(Container):
|
||||
This field is populated if the ETF has short exposure in any of its holdings e.g. in a long/short or inverse ETF. (provider: intrinio)
|
||||
ucits : Optional[bool]
|
||||
If true, the Exchange Traded Product (ETP) is Undertakings for the Collective Investment in Transferable Securities (UCITS) compliant (provider: intrinio)
|
||||
quant_strategies_type : Optional[str]
|
||||
This field is populated if the ETF has either an index-linked or active strategy that is based on a proprietary quantitative strategy. (provider: intrinio)
|
||||
other_quant_models : Optional[str]
|
||||
For ETFs where 'quant_strategies_type' is 'Other Quant Model', this field provides the name of the specific proprietary quant model used as the underlying strategy for the ETF. (provider: intrinio)
|
||||
hedge_fund_type : Optional[str]
|
||||
For ETFs where 'other_asset_types' is 'Hedge Fund Replication', this field provides detail on the type of hedge fund replication strategy. (provider: intrinio)
|
||||
livestock : Optional[str]
|
||||
For ETFs where 'commodity_type' is 'Livestock', this field provides detail on the type of livestock exposure provided by the ETF. (provider: intrinio)
|
||||
registered_countries : Optional[str]
|
||||
The list of countries where the ETF is legally registered for sale. This may differ from where the ETF is domiciled or traded, particularly in Europe. (provider: intrinio)
|
||||
issuer_country : Optional[str]
|
||||
@@ -1064,8 +1066,6 @@ class ROUTER_etf(Container):
|
||||
Base currency in which NAV is reported. (provider: intrinio)
|
||||
listing_currency : Optional[str]
|
||||
Listing currency of the Exchange Traded Product (ETP) in which it is traded. Reported using the 3-digit ISO currency code. (provider: intrinio)
|
||||
income_category : Optional[str]
|
||||
Identifies if an Exchange Traded Fund (ETF) falls into a category that is specifically designed to provide a high yield or income (provider: intrinio)
|
||||
number_of_holdings : Optional[int]
|
||||
The number of holdings in the ETF. (provider: intrinio)
|
||||
month_end_assets : Optional[float]
|
||||
|
||||
Reference in New Issue
Block a user