Skip to content

Commit

Permalink
Merge pull request #588 from yjunechoe/row_distinct-extracts
Browse files Browse the repository at this point in the history
Bugfix `rows_distinct()` dropping non-tested columns
  • Loading branch information
yjunechoe authored Jan 24, 2025
2 parents 4449f9a + 8dd9377 commit 5439790
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# pointblank (development version)

* The `brief` argument of validation functions now also supports `{glue}` syntax (#587)

* Validation step `brief`s correctly recycle to match expanded steps (#564)
- Data extracts for `rows_distinct()` preserves columns other than the ones tested (#588)

- The `brief` argument of validation functions now also supports `{glue}` syntax (#587)

- Validation step `brief`s correctly recycle to match expanded steps (#564)

# pointblank 0.12.2

Expand Down
11 changes: 4 additions & 7 deletions R/interrogate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2392,9 +2392,8 @@ interrogate_distinct <- function(
column_validity_has_columns(columns = column_names)

table %>%
dplyr::select({{ column_names }}) %>%
dplyr::group_by(!!!col_syms) %>%
dplyr::mutate(`pb_is_good_` = ifelse(dplyr::n() == 1, TRUE, FALSE)) %>%
dplyr::mutate(`pb_is_good_` = dplyr::n() == 1L) %>%
dplyr::ungroup()
}

Expand All @@ -2413,15 +2412,13 @@ interrogate_distinct <- function(

unduplicated <-
table %>%
dplyr::select({{ column_names }}) %>%
dplyr::count(!!!col_syms, name = "pb_is_good_") %>%
dplyr::mutate(`pb_is_good_` = ifelse(`pb_is_good_` == 1, TRUE, FALSE)) %>%
dplyr::filter(`pb_is_good_` == TRUE)
dplyr::mutate(`pb_is_good_` = `pb_is_good_` == 1L) %>%
dplyr::filter(`pb_is_good_`)

table %>%
dplyr::select({{ column_names }}) %>%
dplyr::left_join(unduplicated, by = column_names) %>%
dplyr::mutate(`pb_is_good_` = ifelse(is.na(`pb_is_good_`), FALSE, TRUE))
dplyr::mutate(`pb_is_good_` = is.na(`pb_is_good_`))
}

# Perform the validation of the table
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-get_data_extracts.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,16 @@ test_that("Data extracts of different sizes are possible to create", {
get_data_extracts(agent) %>% names() %>% expect_null()
get_data_extracts(agent) %>% length() %>% expect_equal(0)
})

test_that("`rows_distinct()` extracts all columns", {

agent <- create_agent(small_table) %>%
rows_distinct(c(date, date_time)) %>%
interrogate()

expect_identical(
colnames(get_data_extracts(agent)[[1]]),
colnames(small_table)
)

})

0 comments on commit 5439790

Please sign in to comment.