mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
fix symbol validator in standard models (#5839)
Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
This commit is contained in:
@@ -29,25 +29,11 @@ class BalanceSheetQueryParams(QueryParams):
|
||||
default=5, description=QUERY_DESCRIPTIONS.get("limit", "")
|
||||
)
|
||||
|
||||
# pylint: disable=inconsistent-return-statements
|
||||
@field_validator("symbol", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
if v.isdigit() or v.isalpha():
|
||||
return v.upper()
|
||||
raise ValueError(f"Invalid symbol: {v}. Must be either a ticker or CIK.")
|
||||
if isinstance(v, List):
|
||||
symbols = []
|
||||
for symbol in v:
|
||||
if symbol.isdigit() or symbol.isalpha():
|
||||
symbols.append(symbol.upper())
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Invalid symbol: {symbol}. Must be either a ticker or CIK."
|
||||
)
|
||||
return ",".join(symbols)
|
||||
return v.split(",")[0].upper() if "," in v else v.upper()
|
||||
|
||||
|
||||
class BalanceSheetData(Data):
|
||||
|
||||
@@ -26,25 +26,11 @@ class CashFlowStatementQueryParams(QueryParams):
|
||||
default=5, description=QUERY_DESCRIPTIONS.get("limit", "")
|
||||
)
|
||||
|
||||
# pylint: disable=inconsistent-return-statements
|
||||
@field_validator("symbol", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
if v.isdigit() or v.isalpha():
|
||||
return v.upper()
|
||||
raise ValueError(f"Invalid symbol: {v}. Must be either a ticker or CIK.")
|
||||
if isinstance(v, List):
|
||||
symbols = []
|
||||
for symbol in v:
|
||||
if symbol.isdigit() or symbol.isalpha():
|
||||
symbols.append(symbol.upper())
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Invalid symbol: {symbol}. Must be either a ticker or CIK."
|
||||
)
|
||||
return ",".join(symbols)
|
||||
return v.split(",")[0].upper() if "," in v else v.upper()
|
||||
|
||||
|
||||
class CashFlowStatementData(Data):
|
||||
|
||||
@@ -26,25 +26,11 @@ class IncomeStatementQueryParams(QueryParams):
|
||||
default=5, description=QUERY_DESCRIPTIONS.get("limit", "")
|
||||
)
|
||||
|
||||
# pylint: disable=inconsistent-return-statements
|
||||
@field_validator("symbol", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
if v.isdigit() or v.isalpha():
|
||||
return v.upper()
|
||||
raise ValueError(f"Invalid symbol: {v}. Must be either a ticker or CIK.")
|
||||
if isinstance(v, List):
|
||||
symbols = []
|
||||
for symbol in v:
|
||||
if symbol.isdigit() or symbol.isalpha():
|
||||
symbols.append(symbol.upper())
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Invalid symbol: {symbol}. Must be either a ticker or CIK."
|
||||
)
|
||||
return ",".join(symbols)
|
||||
return v.split(",")[0].upper() if "," in v else v.upper()
|
||||
|
||||
|
||||
class IncomeStatementData(Data):
|
||||
|
||||
Reference in New Issue
Block a user