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

profile_sector() now handles case "c" #282

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

profile_sector() now handles case "c" #282

wants to merge 4 commits into from

Conversation

maurolepore
Copy link
Contributor

@maurolepore maurolepore commented Jul 2, 2024


TODO

  • Link related issue/PR.
  • Describe the goal of the PR. Avoid details that are clear in the diff.
  • Mark the PR as draft.
  • Include a unit test.
  • Review your own PR in "Files changed".
  • Ensure the PR branch is updated.
  • Ensure the checks pass.
  • Change the status from draft to ready.
  • Polish the PR description to reflect what it ended up doing.
  • Polish the PR title as you'd like others to read it from the git log.
  • Assign a reviewer.
  • Document user-facing changes in the changelog.

@maurolepore maurolepore changed the title Setup failing test profile_sector() now handles case "c" Jul 2, 2024
Copy link
Contributor Author

@maurolepore maurolepore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalashsinghal and @Tilmon

Here I explore a solution to the bug but I leave it incomplete since fixing this bug requires adapting other tests and maybe code so it would take longer than the time budget I have today.

If you decide this is not worth pursuing, then feel free to close.

Comment on lines -14 to +15
mutate(scenario = recode(.data$scenario, "1.5c rps" = "IPR 1.5c RPS", "nz 2050" = "WEO NZ 2050")) |>
mutate(scenario = ifelse(is.na(scenario), grouped_by, scenario)) |>
mutate(scenario = recode_scenario(.data$scenario)) |>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I write a custom helper to recode scenario in a more robust way. It may be wrong but the idea may be useful. I'll discuss in the helper itself.

Comment on lines -11 to -12
add_avg_matching_certainty("completion") |>
exclude_rows("risk_category")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the main "bug".
This line removes rows where risk_category is NA and therefore drops the rows we would want to output.

Comment on lines +1 to +5
recode_scenario <- function(x) {
out <- gsub("^ipr|^weo", "", x, ignore.case = TRUE)
out <- gsub("_", " ", out)
tolower(trimws(out))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper aims to recode the values of scenario in a more "programatic" way -- trying to avoid using explicit strings and letter-case. The exception here is "ipr" and "weo" -- which we could also eliminate by rewriting the code so that it removes the first word (whatever that is).

If you keep this function do test it because a test suggest we may want something like "ns 2050" but instead we get "ns 2050 2030".

@@ -271,3 +271,37 @@ test_that("outputs `profile_ranking_avg` at company level", {
company <- unnest_company(out)
expect_true(hasName(company, "reduction_targets_avg"))
})

test_that("given a product in 'ipr', when scenarios has also 'weo', then the product-result includes a 'weo*' `scenario` and maps to `NA` in `sector_profile` (#279, tiltIndicator#739)", {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the test for the specific case associated to this issue. Meeting this expectation breaks other tests so the job is incomplete.

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

Successfully merging this pull request may close these issues.

profile_sector() fails to handle case "c"
1 participant