Skip to content

Commit

Permalink
[BugFix] Remove Literal[None,...] (#6371)
Browse files Browse the repository at this point in the history
* remove Literal[None,...]

* pylint: disable=unused-argument

* change  to Filesystem     1K-blocks      Used Available Use% Mounted on
tmpfs            3257224      3044   3254180   1% /run
/dev/nvme0n1p5 491732848 290872352 175808336  63% /
tmpfs           16286112     81500  16204612   1% /dev/shm
tmpfs               5120         8      5112   1% /run/lock
efivarfs             246        66       176  28% /sys/firmware/efi/efivars
tmpfs           16286112         0  16286112   0% /run/qemu
/dev/nvme0n1p1    262144     60008    202136  23% /boot/efi
tmpfs            3257220     15056   3242164   1% /run/user/1000 to avoid misleading linting attr errors
  • Loading branch information
hjoaquim authored May 7, 2024
1 parent 380891d commit 63723f7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 41 deletions.
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

0 comments on commit 63723f7

Please sign in to comment.