finagg.fred.feat package
Module contents
Features from FRED sources.
- finagg.fred.feat.economic
The most popular way for accessing
finagg.fred.feat.Economic
.
- finagg.fred.feat.series
The most popular way for accessing
finagg.fred.feat.Series
.
- class finagg.fred.feat.Economic[source]
Bases:
object
Methods for gathering economic data series from FRED sources.
The module variable
finagg.fred.feat.economic
is an instance of this feature set implementation and is the most popular interface for calling feature methods.Examples
It doesn’t matter which data source you use to gather features. They all return equivalent dataframes.
>>> df1 = finagg.fred.feat.economic.from_api().head(5) >>> df2 = finagg.fred.feat.economic.from_raw().head(5) >>> df3 = finagg.fred.feat.economic.from_refined().head(5) >>> pd.testing.assert_frame_equal(df1, df2, rtol=1e-4) >>> pd.testing.assert_frame_equal(df1, df3, rtol=1e-4)
- classmethod from_api(*, start: None | str = None, end: None | str = None) DataFrame [source]
Get economic features directly from the FRED API.
Not all data series are published at the same rate or time. Missing rows for less-frequent economic series are forward filled.
- Parameters:
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
- Returns:
Economic data series dataframe with each series as a separate column. Sorted by date.
Examples
>>> finagg.fred.feat.economic.from_api().head(5) CIVPART LOG_CHANGE(CPIAUCNS) LOG_CHANGE(CSUSHPINSA) FEDFUNDS ... date ... 2014-10-06 62.8 0.0 0.0 0.09 ... 2014-10-08 62.8 0.0 0.0 0.09 ... 2014-10-13 62.8 0.0 0.0 0.09 ... 2014-10-15 62.8 0.0 0.0 0.09 ... 2014-10-20 62.8 0.0 0.0 0.09 ...
- classmethod from_raw(*, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get economic features from local FRED SQL tables.
Not all data series are published at the same rate or time. Missing rows for less-frequent economic series are forward filled.
- Parameters:
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Economic data series dataframe with each series as a separate column. Sorted by date.
- Raises:
NoResultFound – If there are no rows in the raw SQL table.
Examples
>>> finagg.fred.feat.economic.from_raw().head(5) CIVPART LOG_CHANGE(CPIAUCNS) LOG_CHANGE(CSUSHPINSA) FEDFUNDS ... date ... 2014-10-06 62.8 0.0 0.0 0.09 ... 2014-10-08 62.8 0.0 0.0 0.09 ... 2014-10-13 62.8 0.0 0.0 0.09 ... 2014-10-15 62.8 0.0 0.0 0.09 ... 2014-10-20 62.8 0.0 0.0 0.09 ...
- classmethod from_refined(*, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get features from the feature-dedicated local SQL tables.
This is the preferred method for accessing features for offline analysis (assuming data in the local SQL tables is current).
- Parameters:
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Economic data series dataframe with each series as a separate column. Sorted by date.
- Raises:
NoResultFound – If there are no rows in the refined SQL table.
Examples
>>> finagg.fred.feat.economic.from_refined().head(5) CIVPART LOG_CHANGE(CPIAUCNS) LOG_CHANGE(CSUSHPINSA) FEDFUNDS ... date ... 2014-10-06 62.8 0.0 0.0 0.09 ... 2014-10-08 62.8 0.0 0.0 0.09 ... 2014-10-13 62.8 0.0 0.0 0.09 ... 2014-10-15 62.8 0.0 0.0 0.09 ... 2014-10-20 62.8 0.0 0.0 0.09 ...
- classmethod install(*, engine: None | Engine = None, recreate_tables: bool = False) int [source]
Install economic data by pulling data from the raw SQL tables, transforming them into economic features, and then writing to the refined economic data SQL table.
Tables associated with this method are created if they don’t already exist.
- Parameters:
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.recreate_tables – Whether to drop and recreate tables, wiping all previously installed data.
- Returns:
Number of rows written to the feature’s SQL table.
- classmethod to_refined(df: DataFrame, /, *, engine: None | Engine = None) int [source]
Write the dataframe to the feature store.
- Parameters:
df – Dataframe to store completely as rows in a local SQL table.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the SQL table.
- class finagg.fred.feat.Series[source]
Bases:
object
Get a single economic series as-is from raw FRED data.
The module variable
finagg.fred.feat.series
is an instance of this feature set implementation and is the most popular interface for calling feature methods.- classmethod from_raw(series_id: str, /, *, start: None | str = None, end: None | str = None, engine: None | Engine = None) DataFrame [source]
Get a single economic data series as-is from raw FRED data.
This is the preferred method for accessing raw FRED data without using the FRED API.
- Parameters:
series_id – Economic data series ID.
start – The start date of the observation period. Defaults to the first recorded date.
end – The end date of the observation period. Defaults to the last recorded date.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
A dataframe containing the economic data series values across the specified period.
- Raises:
NoResultFound – If there are no rows for
series_id
in the raw SQL table.
Examples
>>> finagg.fred.feat.series.from_raw("CPIAUCNS").head(5) value date 1949-03-01 169.5 1949-04-01 169.7 1949-05-01 169.2 1949-06-01 169.6 1949-07-01 168.5
- classmethod get_id_set(lb: int = 1, *, engine: None | Engine = None) set[str] [source]
Get all unique economic series IDs in the raw SQL tables that have at least
lb
rows.- Parameters:
lb – Lower bound number of rows that a series must have for its ID to be included in the set returned by this method.
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
Examples
>>> "FEDFUNDS" in finagg.fred.feat.series.get_id_set() True
- classmethod install(series_ids: None | set[str] = None, *, engine: None | Engine = None, recreate_tables: bool = False) int [source]
Install data associated with by pulling data from the FRED API and then writing the data to the raw series SQL table.
Tables associated with this method are created if they don’t already exist.
- Parameters:
series_ids – Set of series to install features for. Defaults to all the series from
finagg.fred.feat.Series.get_id_set
.engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.recreate_tables – Whether to drop and recreate tables, wiping all previously installed data.
- Returns:
Number of rows written to the feature’s SQL table.
- classmethod to_raw(df: DataFrame, /, *, engine: None | Engine = None) int [source]
Write the given dataframe to the raw feature table.
- Parameters:
df – Dataframe to store as rows in a local SQL table
engine – Feature store database engine. Defaults to the engine at
finagg.backend.engine
.
- Returns:
Number of rows written to the SQL table.