Source code for pudl.extract.sec10k
"""Load pre-processed SEC 10-K assets from Google Cloud Storage.
These "raw" tables are generated by the SEC 10-K data extraction pipeline which can be
found in this repository: https://github.com/catalyst-cooperative/mozilla-sec-eia
Upstream data is not partitioned by year, but we want to be able to extract a subset of
the data for testing, so the :class:`Sec10kDataConfig` allow specification of which years
to extract, and those are used to filter the extracted data before returning it.
"""
from io import BytesIO
import dagster as dg
import pandas as pd
from pudl.settings import DataSource, Sec10kDataConfig
from pudl.workspace.datastore import Datastore
[docs]
def raw_sec10k_asset_factory(table) -> dg.AssetsDefinition:
"""An asset factory for extracting SEC 10-K data by table."""
@dg.asset(
group_name="raw_sec10k",
name=table,
required_resource_keys={"datastore", "global_data_config"},
)
def sec10k_asset(context) -> pd.DataFrame:
sec10k_data_config: Sec10kDataConfig = (
context.resources.global_data_config.pudl.sec10k
)
ds: Datastore = context.resources.datastore
if table in sec10k_data_config.tables:
return extract(ds=ds, table=table, years=sec10k_data_config.years)
raise ValueError(f"Unrecognized SEC 10-K table: {table}") # pragma: no cover
return sec10k_asset
[docs]
raw_sec10k_assets = [
raw_sec10k_asset_factory(table)
for table in DataSource.from_id("sec10k").working_partitions["tables"]
]