Merge branch 'develop' into feature/james-didier-feedback

This commit is contained in:
Henrique Joaquim
2024-05-07 12:10:54 +01:00
committed by GitHub
6 changed files with 44 additions and 41 deletions

View File

@@ -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",
)
@@ -89,7 +89,7 @@ class CboeIndexSnapshotsFetcher(
@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"""
@@ -104,12 +104,14 @@ class CboeIndexSnapshotsFetcher(
@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",
@@ -117,10 +119,10 @@ class CboeIndexSnapshotsFetcher(
"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")
@@ -135,9 +137,9 @@ class CboeIndexSnapshotsFetcher(
"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")
]

View File

@@ -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,

View File

@@ -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="""
@@ -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.
@@ -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
@@ -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)

View File

@@ -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,
)

View File

@@ -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."
)
@@ -160,9 +160,9 @@ class PolygonCashFlowStatementFetcher(
@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 = []

View File

@@ -24,7 +24,7 @@ from pydantic import Field, field_validator
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."