SBTi.utils

Module Contents

Functions

get_data_providers(data_providers_configs: List[dict], data_providers_input: List[str]) → List[SBTi.data.DataProvider]

Determines which data provider and in which order should be used.

get_company_data(data_providers: list, company_ids: List[str]) → List[SBTi.interfaces.IDataProviderCompany]

Get the company data in a waterfall method, given a list of companies and a list of data providers. This will go

get_targets(data_providers: list, companies: list) → List[SBTi.interfaces.IDataProviderTarget]

Get the targets in a waterfall method, given a list of companies and a list of data providers. This will go through

_flatten_user_fields(record: SBTi.interfaces.PortfolioCompany)

Flatten the user fields in a portfolio company and return it as a dictionary.

_make_id_map(df_portfolio: pandas.DataFrame) → dict

Create a mapping from company_id to ISIN and LEI (required for the SBTi matching).

dataframe_to_portfolio(df_portfolio: pandas.DataFrame) → List[SBTi.interfaces.PortfolioCompany]

Convert a data frame to a list of portfolio company objects.

get_data(data_providers: List[SBTi.data.DataProvider], portfolio: List[SBTi.interfaces.PortfolioCompany]) → pandas.DataFrame

Get the required data from the data provider(s), validate the targets and return a 9-box grid for each company.

calculate(portfolio_data: pandas.DataFrame, fallback_score: float, aggregation_method: SBTi.portfolio_aggregation.PortfolioAggregationMethod, grouping: Optional[List[str]], scenario: Optional[SBTi.temperature_score.Scenario], time_frames: List[SBTi.interfaces.ETimeFrames], scopes: List[SBTi.interfaces.EScope], anonymize: bool, aggregate: bool = True) → Tuple[pandas.DataFrame, Optional[SBTi.interfaces.ScoreAggregations]]

Calculate the different parts of the temperature score (actual scores, aggregations, column distribution).

Attributes

DATA_PROVIDER_MAP

SBTi.utils.DATA_PROVIDER_MAP :Dict[str, Type[SBTi.data.DataProvider]]
SBTi.utils.get_data_providers(data_providers_configs: List[dict], data_providers_input: List[str]) List[SBTi.data.DataProvider]

Determines which data provider and in which order should be used.

Parameters
  • data_providers_configs – A list of data provider configurations

  • data_providers_input – A list of data provider names

Returns

a list of data providers in order.

SBTi.utils.get_company_data(data_providers: list, company_ids: List[str]) List[SBTi.interfaces.IDataProviderCompany]

Get the company data in a waterfall method, given a list of companies and a list of data providers. This will go through the list of data providers and retrieve the required info until either there are no companies left or there are no data providers left.

Parameters
  • data_providers – A list of data providers instances

  • company_ids – A list of company ids (ISINs)

Returns

A data frame containing the company data

SBTi.utils.get_targets(data_providers: list, companies: list) List[SBTi.interfaces.IDataProviderTarget]

Get the targets in a waterfall method, given a list of companies and a list of data providers. This will go through the list of data providers and retrieve the required info until either there are no companies left or there are no data providers left.

Parameters
  • data_providers – A list of data providers instances

  • companies – A list of companies. Each company should be a dict and contain a company_name and company_id field

Returns

A data frame containing the targets

SBTi.utils._flatten_user_fields(record: SBTi.interfaces.PortfolioCompany)

Flatten the user fields in a portfolio company and return it as a dictionary.

Parameters

record – The record to flatten

Returns

SBTi.utils._make_id_map(df_portfolio: pandas.DataFrame) dict

Create a mapping from company_id to ISIN and LEI (required for the SBTi matching).

Parameters

df_portfolio – The complete portfolio

Returns

A mapping from company_id to (ISIN, LEI) tuple

SBTi.utils.dataframe_to_portfolio(df_portfolio: pandas.DataFrame) List[SBTi.interfaces.PortfolioCompany]

Convert a data frame to a list of portfolio company objects.

Parameters

df_portfolio – The data frame to parse. The column names should align with the attribute names of the

PortfolioCompany model. :return: A list of portfolio companies

SBTi.utils.get_data(data_providers: List[SBTi.data.DataProvider], portfolio: List[SBTi.interfaces.PortfolioCompany]) pandas.DataFrame

Get the required data from the data provider(s), validate the targets and return a 9-box grid for each company.

Parameters
  • data_providers – A list of DataProvider instances

  • portfolio – A list of PortfolioCompany models

Returns

A data frame containing the relevant company-target data

SBTi.utils.calculate(portfolio_data: pandas.DataFrame, fallback_score: float, aggregation_method: SBTi.portfolio_aggregation.PortfolioAggregationMethod, grouping: Optional[List[str]], scenario: Optional[SBTi.temperature_score.Scenario], time_frames: List[SBTi.interfaces.ETimeFrames], scopes: List[SBTi.interfaces.EScope], anonymize: bool, aggregate: bool = True) Tuple[pandas.DataFrame, Optional[SBTi.interfaces.ScoreAggregations]]

Calculate the different parts of the temperature score (actual scores, aggregations, column distribution).

Parameters
  • portfolio_data – The portfolio data, already processed by the target validation module

  • fallback_score – The fallback score to use while calculating the temperature score

  • aggregation_method – The aggregation method to use

  • time_frames – The time frames that the temperature scores should be calculated for (None to calculate all)

  • scopes – The scopes that the temperature scores should be calculated for (None to calculate all)

  • grouping – The names of the columns to group on

  • scenario – The scenario to play

  • anonymize – Whether to anonymize the resulting data set or not

  • aggregate – Whether to aggregate the scores or not

Returns

The scores, the aggregations and the column distribution (if a