2DegreesInvesting / tiltIndicator

Implement the core business logic of the tilt indicators
https://2degreesinvesting.github.io/tiltIndicator/
GNU General Public License v3.0
1 stars 1 forks source link

Warn if `companies$*sector` has semicolon ";" #448

Closed maurolepore closed 1 year ago

maurolepore commented 1 year ago

In PSTR the companies dataset had multiple sectors and subsectors squashed into a single string with semicolon ";" as separator -- a bug that caused many missmatches (#439). We expect new companies to not have that bug but we need to assert it to avoid a regression.


I am right now updating the sector mappers so that this case with ";" ideally won't happen again.

Originally posted by @Tilmon in https://github.com/2DegreesInvesting/tiltIndicator/issues/439#issuecomment-1611332487

maurolepore commented 1 year ago
devtools::load_all()
#> ℹ Loading tiltIndicator

companies <- tiltIndicator::pstr_companies
# Introduce a problematic value to trigger the new warning
companies[1, "sector"] <- "a; b"
scenarios <- tiltIndicator::xstr_scenarios

pstr(companies, scenarios)
#> Warning: The `*sector` columns used to match scenarios shouln't have semicolon ';'.
#> ✖ Unmatched values of `sector` and `subsector` result in `NA`s.
#> ℹ Do you need see the evolution of this issue on GitHub (#448)?
#> # A tibble: 14 × 3
#>    companies_id                             product           company          
#>    <chr>                                    <list>            <list>           
#>  1 fleischerei-stiefsohn_00000005219477-001 <tibble [12 × 9]> <tibble [36 × 3]>
#>  2 pecheries-basques_fra316541-00101        <tibble [14 × 9]> <tibble [42 × 3]>
#>  3 hoche-butter-gmbh_deu422723-693847001    <tibble [14 × 9]> <tibble [42 × 3]>
#>  4 hoche-butter-gmbh_deu422723-693847002    <tibble [14 × 9]> <tibble [42 × 3]>
#>  5 hoche-butter-gmbh_deu422723-693847003    <tibble [14 × 9]> <tibble [42 × 3]>
#>  6 vicquelin-espaces-verts_fra697272-00101  <tibble [14 × 9]> <tibble [42 × 3]>
#>  7 vicquelin-espaces-verts_fra697272-00102  <tibble [14 × 9]> <tibble [42 × 3]>
#>  8 vicquelin-espaces-verts_fra697272-00103  <tibble [14 × 9]> <tibble [42 × 3]>
#>  9 fleisohn_0000000492-001                  <tibble [14 × 9]> <tibble [42 × 3]>
#> 10 bst-procontrol-gmbh_00000005104947-001   <tibble [14 × 9]> <tibble [42 × 3]>
#> 11 leider-gmbh_00000005064318-001           <tibble [14 × 9]> <tibble [42 × 3]>
#> 12 leider-gmbh_00000005064318-002           <tibble [14 × 9]> <tibble [42 × 3]>
#> 13 cheries-baqu_neu316541-00101             <tibble [14 × 9]> <tibble [42 × 3]>
#> 14 ca-coity-trg-aua-gmbh_00000384-001       <tibble [14 × 9]> <tibble [42 × 3]>

Created on 2023-06-28 with reprex v2.0.2