imf

Authors: Sou-Cheng T. Choi and Irina Klein, Illinois Institute of Technology Updated Date: Dec 7, 2022 Creation Date: Jun 15, 2022

Module Contents

Classes

Series

Helper class that provides a standard way to create an ABC using

IMF

Helper class that provides a standard way to create an ABC using

AFRREO

Sub-Saharan Africa Regional Economic Outlook (AFRREO). A child class of IMF.

IFS

International Financial Statistics (IFS). A child class of IMF.

DOT

Direction of Trade Statistics (DOT). A child class of IMF.

BOP

Balance of Payments (BOP). A child class of IMF.

FSI

Financial Soundness Indicators (FSIs). A child class of IMF.

GFSR

Government Finance Statistics (GFS), Revenue. A child class of IMF.

COFOG

Government Finance Statistics (GFS), Expenditure by Function of Government (COFOG). A child class of IMF.

HPDD

Historical Public Debt Database (HPDD). A child class of IMF.

Attributes

MAX_FILENAME_LEN

imf.MAX_FILENAME_LEN = 260
class imf.Series(series='IFS', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

get_series_names()
abstract download_meta()
abstract download_data()
abstract get_meta()
abstract get_data()
abstract describe_meta()
abstract describe_data()
class imf.IMF(series='IFS', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: Series

Helper class that provides a standard way to create an ABC using inheritance.

output_series(series=None)

This function outputs all or some IMF series dataframe to a csv file, and logs its file path.

Parameters

series – Series code as a string. If series is None, then the function outputs all series to a csv file. If series is not None, then the function outputs only the series that contain the string series to a csv file.

output_dim(dim_name=None)

This function outputs all or some dimension tables to a .csv file in ‘out’

Parameters

dim_name – Dimension name as a string

output_meta(indicator=None)

Method to output all or some indicators in a tables to a .csv file in ‘out’

Parameters

indicator – Indicator code as a string

output_data(is_gen_filename=False)

This function outputs the data to a csv file.

Parameters

is_gen_filename – generate the csv file name from user inputs if True, defaults to False

gen_data_filename(is_meta=False)

It takes the search terms, countries, period, start time, and end time, and creates a filename for the data up to 250 characters

Parameters

is_meta – whether to generate a filename for the meta data or the actual data, defaults to False

(optional). Defaults to False

Returns

The filename and the search terms

get_series_names()

It takes a list of series names, and returns a dataframe with the series names and their corresponding IDs

Returns

A dataframe with the series names and their corresponding IDs.

get_dimensions()

It downloads the dimensions of the series, and then downloads the details of each dimension

download_meta()

The function downloads the meta data of the time series from the IMF API

Returns

The meta data of the time series.

read_meta_df()

The function reads a csv file into a Pandas dataframe, renames the columns, and then cleans the column names.

read_dim_df(dim_name='CL_FREQ')

The function reads a csv file with dimension data into a Pandas dataframe.

Parameters

dim_name – name of dimension

download_data()

It downloads data and its meta data from the IMF web server, and saves it to a csv file.

Returns

The data is being returned as a pandas dataframe.

validate_inputs()

The function checks if the user inputs are valid. It will change an invalid input to a valid value with a warning.

clean_column_names(df)

It replaces special characters in all column names and makes them upper case

Parameters

df – The Pandas dataframe to be cleaned

Returns

The Pandas dataframe with the cleaned column names.

repeat_request(url)

It will try to get a response from the IMF data server for a given url, and if it doesn’t get a response, it will wait a few seconds and try again

Parameters

url – the url to request

Returns

The json object is being returned. It will returns None if it does not get a valid response after making a few requests to the IMF data server.

get_meta()

This function returns the meta data of the IMF economic indicator(s).

Returns

The meta data of the time series data

get_data()

This function returns the time series data.

Returns

The dataframe of the time series data.

describe_data()

The function returns a summary of data.

Returns

A Pandas dataframe that contains the summary statistics of the data.

describe_meta()

This function takes the meta data dataframe and returns a summary of the meta data.

Returns

Summary of meta data

class imf.AFRREO(series='AFRREO', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Sub-Saharan Africa Regional Economic Outlook (AFRREO). A child class of IMF.

class imf.IFS(series='IFS', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

International Financial Statistics (IFS). A child class of IMF.

class imf.DOT(series='DOT', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Direction of Trade Statistics (DOT). A child class of IMF.

class imf.BOP(series='BOP', search_terms=None, countries=None, period='Q', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Balance of Payments (BOP). A child class of IMF.

class imf.FSI(series='FSI', search_terms=None, countries=None, period='M', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Financial Soundness Indicators (FSIs). A child class of IMF.

class imf.GFSR(series='GFSR', search_terms=None, countries=None, period='A', start_date=None, end_date=None, sector='', unit='', outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Government Finance Statistics (GFS), Revenue. A child class of IMF.

download_data()

It downloads data and its meta data from the IMF web server, and saves it to a csv file.

Returns

The data is being returned as a pandas dataframe.

class imf.COFOG(series='COFOG', search_terms=None, countries=None, period='A', start_date=None, end_date=None, outdir=None)

Bases: IMF

Government Finance Statistics (GFS), Expenditure by Function of Government (COFOG). A child class of IMF.

class imf.HPDD(series='HPDD', search_terms=None, countries=None, period='A', start_date=None, end_date=None, outdir='out', logdir='log', is_log_to_screen=True)

Bases: IMF

Historical Public Debt Database (HPDD). A child class of IMF.