Skip to content

Commit

Permalink
[BugFix] SecCompanyFilings: Purge nan Values & Make form_type Mat…
Browse files Browse the repository at this point in the history
…ch (#6846)

* purge nan values and put word boundaries on form_type filter.

* just replace nan at the output

* use isin instead
  • Loading branch information
deeleeramone authored Oct 23, 2024
1 parent da0ba41 commit f8a45fa
Showing 1 changed file with 6 additions and 13 deletions.
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

0 comments on commit f8a45fa

Please sign in to comment.