Skip to content

Commit 6ca90bf

Browse files
Merge pull request #116 from r-lib/sparse_is_ns-bug
2 parents 71ee2d3 + f4c3fa7 commit 6ca90bf

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Fixed bug where `sparse_multiplication()` had a stack imbalence when returning all 0s. (#113)
44

5+
* Fixed bug where `sparse_is_na(type = "integer")` would error on character vectors. (#116)
6+
57
# sparsevctrs 0.3.3
68

79
## Bug Fixes

R/sparse_is_na.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sparse_is_na <- function(x, type = "logical") {
4444
rep(1, length(positions)),
4545
positions,
4646
length(x),
47-
sparse_default(x)
47+
0L
4848
)
4949
}
5050

tests/testthat/test-sparse_is_na.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,46 @@ test_that("sparse_is_na() works - double", {
22
x <- sparse_double(c(10, -10), c(5, 100), 1000)
33

44
expect_equal(is.na(x), sparse_is_na(x))
5+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
56

67
x <- sparse_double(c(NA, 10, 30), 1:3, 1000)
78

89
expect_equal(is.na(x), sparse_is_na(x))
10+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
911
})
1012

1113
test_that("sparse_is_na() works - integer", {
1214
x <- sparse_integer(c(10, -10), c(5, 100), 1000)
1315

1416
expect_equal(is.na(x), sparse_is_na(x))
17+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
1518

1619
x <- sparse_integer(c(NA, 10, 30), 1:3, 1000)
1720

1821
expect_equal(is.na(x), sparse_is_na(x))
22+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
1923
})
2024

2125
test_that("sparse_is_na() works - logical", {
2226
x <- sparse_logical(c(TRUE, TRUE), c(5, 100), 1000)
2327

2428
expect_equal(is.na(x), sparse_is_na(x))
29+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
2530

2631
x <- sparse_logical(c(NA, TRUE, TRUE), 1:3, 1000)
2732

2833
expect_equal(is.na(x), sparse_is_na(x))
34+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
2935
})
3036

3137
test_that("sparse_is_na() works - character", {
3238
x <- sparse_character(c("A", "B"), c(5, 100), 1000)
3339

3440
expect_equal(is.na(x), sparse_is_na(x))
41+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
3542

3643
x <- sparse_character(c(NA, "A", "B"), 1:3, 1000)
3744

3845
expect_equal(is.na(x), sparse_is_na(x))
46+
expect_equal(as.integer(is.na(x)), sparse_is_na(x, type = "integer"))
3947
})

0 commit comments

Comments
 (0)