Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite not passing following recent changes #287

Open
tepelbaum opened this issue Sep 16, 2022 · 1 comment
Open

Test suite not passing following recent changes #287

tepelbaum opened this issue Sep 16, 2022 · 1 comment

Comments

@tepelbaum
Copy link

tepelbaum commented Sep 16, 2022

Hi!

Thanks a lot for this great library :). I was using the latest github version but noticed that the test suite is broken. Maybe it could be good to add a github workflow running the test suite? Or at least to fix the test/code to show the correct intent :).

One of the cases I have in mind is (It's not the only one that needs fixing if I am not mistaken)

company_name company_id isic target_type intensity_metric scope emissions_in_scope reduction_ambition base_year start_year end_year achieved_reduction target_status time_frame industry ghg_s1s2 ghg_s3 company_market_cap investment_value portfolio_weight company_cash_equivalents company_enterprise_value company_ev_plus_cash company_total_assets sbti_validated
Company T CA0000000020 A12 Absolute Revenue S1+S2 100 0.416 2009 2009 2020 0.68 Underway short test 28400000 28400000 66682 18472 0.055325267 22005.06 15403.542 62681.08 60680.62 1

One line of the data_test_temperature_score.csv file

Here the end_year is 2020. If we go into

    def get_annual_reduction_rate(self, target: pd.Series) -> Optional[float]:
        """
        Get the annual reduction rate (or None if not available).

        :param target: The target as a row of a dataframe
        :return: The annual reduction
        """

        # 2022-09-01 Bloomberg pointed out need for additional checks in input
        # Here is the original code:
        # if pd.isnull(target[self.c.COLS.REDUCTION_AMBITION]):
        #     return None

        # try:
        #     return target[self.c.COLS.REDUCTION_AMBITION] / float(
        #         target[self.c.COLS.END_YEAR] - target[self.c.COLS.BASE_YEAR]
        #     )
        # except ZeroDivisionError:
        #     raise ValueError(
        #         "Couldn't calculate the annual reduction rate because the start and target year are the "
        #         "same"
        #     )

        # Bloombergs proposal - changed 2022-09-01
        check = pd.isnull(target[self.c.COLS.REDUCTION_AMBITION])
        check = check or pd.isnull(target[self.c.COLS.END_YEAR])
        check = check or pd.isnull(target[self.c.COLS.BASE_YEAR])
        check = check or (target[self.c.COLS.END_YEAR] <= target[self.c.COLS.BASE_YEAR])
        # add check that target is not too old
        check = check or (target[self.c.COLS.END_YEAR] < datetime.datetime.now().year)
        if check:
            return None
        return target[self.c.COLS.REDUCTION_AMBITION] / float(
            target[self.c.COLS.END_YEAR] - target[self.c.COLS.BASE_YEAR]
        )
        # End of BBGs code

We see that the last check puts NaN into self.c.COLS.ANNUAL_REDUCTION_RATE, thus giving a final temperature of 3.2, whereas in the test we find:

  scores = self.temperature_score.calculate(self.data)
        self.assertAlmostEqual(
            scores[
                (scores["company_name"] == "Company T")
                & (scores["scope"] == EScope.S1S2)
            ]["temperature_score"].iloc[0],
            1.77,
            places=2,
            msg="The temp score was incorrect",
        )

1.77 :)

@mountainrambler
Copy link
Contributor

Thanks for bringing this up; and sorry for the very late response.
Obviously, a target with an end date in 2020 would be invalid. So we'll take a look at updating the test file as well as finding some enhanced workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants