ScienceBasedTargets / SBTi-finance-tool

This toolkit helps companies and financial institutions to assess the temperature alignment of current targets, commitments, and investment and lending portfolios, and to use this information to develop targets for official validation by the SBTi. See the wiki for a change log.
https://sciencebasedtargets.org/
MIT License
49 stars 42 forks source link

Pydantic validation error when running script number 2 from Google Collab #304

Open lukasdenkstatt opened 1 year ago

lukasdenkstatt commented 1 year ago

Hi there,

I downloaded the code for the SBTI finance tool from GitHub and also downloaded the scripts from Google Collab. I tried to run the second script "2_quick_temp_score_calculation" and I get the following error:

Traceback (most recent call last): File "C:\Users\lukas.schiele\Desktop\SBTi-finance-tool-main\2_quick_temp_score_calculation.py", line 79, in companies = SBTi.utils.dataframe_to_portfolio(df_portfolio) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\lukas.schiele\Desktop\SBTi-finance-tool-main\SBTi\utils.py", line 196, in dataframe_to_portfolio return [ ^ File "C:\Users\lukas.schiele\Desktop\SBTi-finance-tool-main\SBTi\utils.py", line 197, in PortfolioCompany.model_validate(company) File "C:\Users\lukas.schiele\Desktop\pythonprojects\SBTi-finance-tool-main\Lib\site-packages\pydantic\main.py", line 496, in model_validate return cls.__pydantic_validator__.validate_python( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 1 validation error for PortfolioCompany user_fields Field required [type=missing, input_value={'company_name': 'Company...ngagement_target': True}, input_type=dict] For further information visit https://errors.pydantic.dev/2.1/v/missing

Process finished with exit code 1

What do I need to do to resolve this error?

chowdud commented 1 year ago

Hi, I'm also receiving the same issue as @lukasdenkstatt and this appears in the first script for "Analysis" too. It looks to originate from SBTi.utils.dataframe_to_portfolio, but upon further inspection of the method, the PortfolioCompany model clearly defines "user_fields" as optional. Any updates on what may be the issue here?

chowdud commented 1 year ago

@lukasdenkstatt I think I may have it working now. Can you confirm where you are installing your requirements.txt packages as well as the venv you are using (local or global)?

lukasdenkstatt commented 12 months ago

@chowdud Good to hear that it works for you!

One requirements.txt package is installed in the folder "SBTi-finance-tool-main" and the other under "SBTi-finance-tool-main/examples". I think I am using a local venv.

Thanks for your help!