SBTi.utils

Module Contents

Functions

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

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

get_company_data(data_providers: list, company_ids: List[str]) → List[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[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: PortfolioCompany)

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

_make_isin_map(df_portfolio: pd.DataFrame) → dict

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

dataframe_to_portfolio(df_portfolio: pd.DataFrame) → List[PortfolioCompany]

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

get_data(data_providers: List[data.DataProvider], portfolio: List[PortfolioCompany]) → pd.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: pd.DataFrame, fallback_score: float, aggregation_method: PortfolioAggregationMethod, grouping: Optional[List[str]], scenario: Optional[Scenario], time_frames: List[ETimeFrames], scopes: List[EScope], anonymize: bool, aggregate: bool = True) → Tuple[pd.DataFrame, Optional[ScoreAggregations]]

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

SBTi.utils.DATA_PROVIDER_MAP :Dict[str, Type[data.DataProvider]]
SBTi.utils.get_data_providers(data_providers_configs: List[dict], data_providers_input: List[str]) → List[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[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[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: 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_isin_map(df_portfolio: pd.DataFrame) → dict

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

Parameters

df_portfolio – The complete portfolio

Returns

A mapping from company_id to ISIN

SBTi.utils.dataframe_to_portfolio(df_portfolio: pd.DataFrame) → List[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[data.DataProvider], portfolio: List[PortfolioCompany]) → pd.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: pd.DataFrame, fallback_score: float, aggregation_method: PortfolioAggregationMethod, grouping: Optional[List[str]], scenario: Optional[Scenario], time_frames: List[ETimeFrames], scopes: List[EScope], anonymize: bool, aggregate: bool = True) → Tuple[pd.DataFrame, Optional[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