Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Remove Literal[None,...] #6371

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CboeIndexSnapshotsQueryParams(IndexSnapshotsQueryParams):
Source: https://www.cboe.com/
"""

region: Literal[None, "us", "eu"] = Field(
region: Optional[Literal["us", "eu"]] = Field(
default="us",
)

Expand Down Expand Up @@ -89,7 +89,7 @@ def transform_query(params: Dict[str, Any]) -> CboeIndexSnapshotsQueryParams:
@staticmethod
async def aextract_data(
query: CboeIndexSnapshotsQueryParams,
credentials: Optional[Dict[str, str]],
credentials: Optional[Dict[str, str]], # pylint: disable=unused-argument
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the Cboe endpoint"""
Expand All @@ -104,23 +104,25 @@ async def aextract_data(

@staticmethod
def transform_data(
query: CboeIndexSnapshotsQueryParams, data: dict, **kwargs: Any
query: CboeIndexSnapshotsQueryParams, # pylint: disable=unused-argument
data: dict,
**kwargs: Any, # pylint: disable=unused-argument
) -> List[CboeIndexSnapshotsData]:
"""Transform the data to the standard format"""
if not data:
raise EmptyDataError()
data = DataFrame(data)
df = DataFrame(data)
percent_cols = [
"price_change_percent",
"iv30",
"iv30_change",
"iv30_change_percent",
]
for col in percent_cols:
if col in data.columns:
data[col] = round(data[col] / 100, 6)
data = (
data.replace(0, None)
if col in df.columns:
df[col] = round(df[col] / 100, 6)
df = (
df.replace(0, None)
.replace("", None)
.dropna(how="all", axis=1)
.fillna("N/A")
Expand All @@ -135,9 +137,9 @@ def transform_data(
"bid_size",
]
for col in drop_cols:
if col in data.columns:
data = data.drop(columns=col)
if col in df.columns:
df = df.drop(columns=col)
return [
CboeIndexSnapshotsData.model_validate(d)
for d in data.to_dict(orient="records")
for d in df.to_dict(orient="records")
]
4 changes: 2 additions & 2 deletions openbb_platform/providers/fred/openbb_fred/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class FredSearchQueryParams(SearchQueryParams):
default=0,
description="Offset the results in conjunction with limit.",
)
filter_variable: Literal[None, "frequency", "units", "seasonal_adjustment"] = Field(
default=None, description="Filter by an attribute."
filter_variable: Optional[Literal["frequency", "units", "seasonal_adjustment"]] = (
Field(default=None, description="Filter by an attribute.")
)
filter_value: Optional[str] = Field(
default=None,
Expand Down
45 changes: 23 additions & 22 deletions openbb_platform/providers/fred/openbb_fred/models/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ class FredSeriesQueryParams(SeriesQueryParams):
}
__json_schema_extra__ = {"symbol": ["multiple_items_allowed"]}

frequency: Literal[
None,
"a",
"q",
"m",
"w",
"d",
"wef",
"weth",
"wew",
"wetu",
"wem",
"wesu",
"wesa",
"bwew",
"bwem",
frequency: Optional[
Literal[
"a",
"q",
"m",
"w",
"d",
"wef",
"weth",
"wew",
"wetu",
"wem",
"wesu",
"wesa",
"bwew",
"bwem",
]
] = Field(
default=None,
description="""
Expand All @@ -67,7 +68,7 @@ class FredSeriesQueryParams(SeriesQueryParams):
bwem = Biweekly, Ending Monday
""",
)
aggregation_method: Literal[None, "avg", "sum", "eop"] = Field(
aggregation_method: Optional[Literal["avg", "sum", "eop"]] = Field(
default="eop",
description="""
A key that indicates the aggregation method used for frequency aggregation.
Expand All @@ -77,10 +78,11 @@ class FredSeriesQueryParams(SeriesQueryParams):
eop = End of Period
""",
)
transform: Literal[None, "chg", "ch1", "pch", "pc1", "pca", "cch", "cca", "log"] = (
Field(
default=None,
description="""
transform: Optional[
Literal["chg", "ch1", "pch", "pc1", "pca", "cch", "cca", "log"]
] = Field(
default=None,
description="""
Transformation type
None = No transformation
chg = Change
Expand All @@ -92,7 +94,6 @@ class FredSeriesQueryParams(SeriesQueryParams):
cca = Continuously Compounded Annual Rate of Change
log = Natural Log
""",
)
)
limit: int = Field(description=QUERY_DESCRIPTIONS.get("limit", ""), default=100000)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GovernmentUSTreasuryPricesQueryParams(TreasuryPricesQueryParams):
"""US Government Treasury Prices Query."""

cusip: Optional[str] = Field(description="Filter by CUSIP.", default=None)
security_type: Literal[None, "bill", "note", "bond", "tips", "frn"] = Field(
security_type: Optional[Literal["bill", "note", "bond", "tips", "frn"]] = Field(
description="Filter by security type.",
default=None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class PolygonCashFlowStatementQueryParams(CashFlowStatementQueryParams):
default=False,
description="Whether to include the sources of the financial statement.",
)
order: Literal[None, "asc", "desc"] = Field(
order: Optional[Literal["asc", "desc"]] = Field(
default=None, description="Order of the financial statement."
)
sort: Literal[None, "filing_date", "period_of_report_date"] = Field(
sort: Optional[Literal["filing_date", "period_of_report_date"]] = Field(
default=None, description="Sort of the financial statement."
)

Expand Down Expand Up @@ -160,9 +160,9 @@ async def aextract_data(

@staticmethod
def transform_data(
query: PolygonCashFlowStatementQueryParams,
query: PolygonCashFlowStatementQueryParams, # pylint: disable=unused-argument
data: dict,
**kwargs: Any,
**kwargs: Any, # pylint: disable=unused-argument
) -> List[PolygonCashFlowStatementData]:
"""Return the transformed data."""
transformed_data = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class TmxIndexSnapshotsQueryParams(IndexSnapshotsQueryParams):
"""TMX Index Snapshots Query Params."""

region: Literal[None, "ca", "us"] = Field(default="ca") # type: ignore
region: Optional[Literal["ca", "us"]] = Field(default="ca") # type: ignore
use_cache: bool = Field(
default=True,
description="Whether to use a cached request."
Expand Down
Loading