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] SecCompanyFilings: Purge nan Values & Make form_type Match #6846

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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
19 changes: 6 additions & 13 deletions openbb_platform/providers/sec/openbb_sec/models/company_filings.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def transform_data(
) -> List[SecCompanyFilingsData]:
"""Transform the data."""
# pylint: disable=import-outside-toplevel
from pandas import DataFrame, to_datetime
from numpy import nan
from pandas import NA, DataFrame, to_datetime

if not data:
raise EmptyDataError(
Expand All @@ -305,12 +306,7 @@ def transform_data(
"isXBRL",
"size",
]
filings = (
DataFrame(data, columns=cols)
.fillna(value="N/A")
.replace("N/A", None)
.astype(str)
)
filings = DataFrame(data, columns=cols).astype(str)
filings["reportDate"] = to_datetime(filings["reportDate"]).dt.date
filings["filingDate"] = to_datetime(filings["filingDate"]).dt.date
filings = filings.sort_values(by=["reportDate", "filingDate"], ascending=False)
Expand All @@ -332,17 +328,14 @@ def transform_data(
base_url + filings["accessionNumber"] + "-index.htm"
)
if query.form_type:
form_types = query.form_type.replace("_", " ").replace(",", "|")

filings = filings[
filings.form.str.contains(form_types, case=False, regex=True, na=False)
]

form_types = query.form_type.replace("_", " ").split(",")
filings = filings[filings.form.isin(form_types)]
if query.limit:
filings = filings.head(query.limit) if query.limit != 0 else filings

if len(filings) == 0:
raise EmptyDataError("No filings were found using the filters provided.")
filings = filings.replace({NA: None, nan: None})

return [
SecCompanyFilingsData.model_validate(d) for d in filings.to_dict("records")
Expand Down
Loading