cowidev.vax.utils¶
cowidev.vax.utils.base¶
- class cowidev.vax.utils.base.CountryVaxBase[source]¶
Bases:
object
- _export_datafile_main(df, filename, attach=False, reset_index=False, valid_cols_only=False, **kwargs)[source]¶
Export main data.
- _export_datafile_secondary(df, metadata, output_path, output_path_meta)[source]¶
Export secondary data.
- _postprocessing(df, valid_cols_only)[source]¶
Minor post processing after all transformations.
Basically sort by date, ensure correct column order, correct type for metrics.
- _postprocessing_age(df)[source]¶
Minor post processing after all transformations.
Basically sort by date, ensure correct column order, correct type for metrics.
- _postprocessing_manufacturer(df)[source]¶
Minor post processing after all transformations.
Basically sort by date, ensure correct column order, correct type for metrics.
- export_datafile(df=None, df_age=None, df_manufacturer=None, meta_age=None, meta_manufacturer=None, filename=None, attach=False, attach_age=False, attach_manufacturer=False, reset_index=False, valid_cols_only=False, **kwargs)[source]¶
Export country data.
- Parameters:
df (pd.DataFrame) – Main country data.
df_age (pd.DataFrame, optional) – Country data by age group. Defaults to None.
df_manufacturer (pd.DataFrame, optional) – Country data by manufacturer. Defaults to None.
meta_age (dict, optional) – Country metadata by age. Defaults to None.
meta_manufacturer (dict, optional) – Country metadata by manufacturer. Defaults to None.
filename (str, optional) – Name of output file. If None, defaults to country name.
attach (bool, optional) – Set to True to attach to already existing data. Defaults to False.
attach_age (bool, optional) – Set to True to attach to already existing data. Defaults to False.
attach_manufacturer (bool, optional) – Set to True to attach to already existing data. Defaults to False.
valid_cols_only (bool, optional) – Export only valid columns. Defaults to False.
reset_index (bool, optional) – Brin index back as a column. Defaults to False.
- location: str = None¶
- property output_path¶
Country output file.
- property output_path_age¶
Country output file for age-group data.
- property output_path_manufacturer¶
Country output file for manufacturer data.
cowidev.vax.utils.checks¶
- class cowidev.vax.utils.checks.CountryChecker(df: DataFrame, allow_extra_cols: bool = True, monotonic_check_skip: list = [], anomalies: bool = True, anomaly_check_skip: list = [])[source]¶
Bases:
object
- property metrics_present¶
cowidev.vax.utils.extra_source¶
cowidev.vax.utils.files¶
- cowidev.vax.utils.files.export_metadata(df: DataFrame, source_name: str, source_url: str, output_path: str)[source]¶
- cowidev.vax.utils.files.load_data(data_filename: str, file_ext: str = 'csv')[source]¶
Load a data from a file in vax._static folder.
- Parameters:
data_filename (str) – Name of the data file. If no extension is provided, {query_filename}.{file_ext} will be loaded
file_ext (str, optional) – Extension of the file. Defaults to “csv”.
- Raises:
FileNotFoundError – If no file is found
ValueError – If non-supported format is provided
- Returns:
Loaded query as a string
- Return type:
dict
- cowidev.vax.utils.files.load_query(query_filename: str, file_ext: str = 'json', to_str: bool = True)[source]¶
Load a query from a file in vax._static folder.
- Parameters:
query_filename (str) – Name of the query file. If no extension is provided, {query_filename}.{file_ext} will be loaded
file_ext (str, optional) – Extension of the file. Defaults to “json”.
- Raises:
FileNotFoundError – If no file is found
ValueError – If non-supported format is provided
- Returns:
Loaded query as a string
- Return type:
dict
cowidev.vax.utils.incremental¶
- cowidev.vax.utils.incremental._build_df(location, total_vaccinations, date, vaccine, source_url, people_vaccinated=None, people_partly_vaccinated=None, people_fully_vaccinated=None, total_boosters=None)[source]¶
- cowidev.vax.utils.incremental._check_fields(location, source_url, vaccine, date, total_vaccinations, people_vaccinated, people_partly_vaccinated, people_fully_vaccinated, total_boosters)[source]¶
- cowidev.vax.utils.incremental._increment(filepath, location, total_vaccinations, date, vaccine, source_url, people_vaccinated=None, people_partly_vaccinated=None, people_fully_vaccinated=None, total_boosters=None)[source]¶
cowidev.vax.utils.utils¶
- cowidev.vax.utils.utils.add_latest_who_values(df: DataFrame, who_location_name: str, metrics: list)[source]¶
Inserts the latest data available from the WHO vaccination dataset into the existing dataframe. metrics: list of metrics to be used from the WHO dataset. Other metrics that aren’t listed will be automatically set to pd.NA for this specific row.
- cowidev.vax.utils.utils.build_vaccine_timeline(df: DataFrame, vaccine_timeline: dict) DataFrame [source]¶
Add vaccines to the data based on admin. starting date.
vaccine_timeline: dictionary of “vaccine” -> “start_date”
Example:
- {
“Pfizer/BioNTech”: “2021-02-24”, “Sinovac”: “2021-03-03”, “Oxford/AstraZeneca”: “2021-05-03”, “CanSino”: “2021-05-09”, “Sinopharm”: “2021-09-18”,
}