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

Fix tests for complex #5796

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -9935,7 +9935,7 @@ test(1658.56, fwrite(data.table(exp(1) - pi*1i)), output='2.718[0-9]*-3.141[0-9]
## formerly 1658.46
DT = data.table(a=1:3, b=list(1:4, c(3.14, 100e10), c(3i,4i,5i)))
test(1658.57, fwrite(DT), output='0+3i|0+4i|0+5i')
DT[ , b := c(1i, -1-1i, NA)]
DT[ , b := c(1i, -1-1i, NA_complex_)]
test(1658.58, fwrite(DT), output='a,b\n1,0\\+1i\n2,-1-1i\n3,$')

# more coverage
Expand Down Expand Up @@ -10964,7 +10964,7 @@ test(1743.217, sapply(fread("a,b,c,d,e,f\na,b,c,d,e,f", colClasses = list(factor
test(1743.218, sapply(fread("a,b,c,d,e,f\na,b,c,d,e,f", colClasses = list(factor = c(1, 2, 4), factor = 3), select = c(5, 4, 2, 3)), class), y = c(e = "character", d = "factor", b = "factor", c = "factor"))

test(1743.22, fread("a,b,c\n1999/01/01,2,f", colClasses=list(Date=1L), drop="a"), data.table(b=2L, c="f"))
test(1743.231, fread("a,b,c\n2,1,4i", colClasses=list(complex="c", integer=2L), drop="a"), data.table(b=1L, c="4i"),
test(1743.231, fread("a,b,c\n2,1,4j", colClasses=list(complex="c", integer=2L), drop="a"), data.table(b=1L, c="4j"),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a substantial improvement in r-devel -- previously it seems as.complex("4i") would fail to coerce which seems wrong. Better to try and coerce to complex something that's not actually complex, to ensure the warning continues.

cc original author @HughParsonage in case I'm missing something behind the intent of this test.

Copy link
Member

Choose a reason for hiding this comment

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

I think Matt added that specific test, though I added the tests around it, which looks to have been a back and forth that observed but did not mention the behaviour of as.complex("4i"):

c6e2b72#diff-e3243f3780ce7d303c3317f73945310bfc37e45d193568246246aca20e3270ae

warning=paste0(base_messages$coerce_na, ".*left as type 'character'"))
test(1743.232, fread("a,b,c\n2,1,3+4i", colClasses=list(complex="c", integer=2L), drop="a"), data.table(b=1L, c=3+4i))
test(1743.241, fread("a,b,c\n2,2,f", colClasses = list(character="c", integer="b"), drop="a"), data.table(b=2L, c="f"))
Expand Down Expand Up @@ -15406,9 +15406,9 @@ test(2060.503, xx_addr, address(xx))
test(2060.504, xx, x)
test(2060.505, address(setcoalesce(xx)), xx_addr)
# complex support for fcoalesce
z1 = c(1i, NA, 1-1i, NA, 0+3i, NA)
z2 = c(NA, 4-2i, 0+0i, NA, NA, NA)
z3 = c(2, NA, 3+6i, 5-1i, NA, NA)
z1 = c(1i, NA_complex_, 1-1i, NA_complex_, 0+3i, NA_complex_)
z2 = c(NA_complex_, 4-2i, 0+0i, NA_complex_, NA_complex_, NA_complex_)
z3 = c(2, NA_complex_, 3+6i, 5-1i, NA_complex_, NA_complex_)
na_idx = c(2L, 4L, 6L)
test(2060.600, fcoalesce(z1, 0+0i), `[<-`(z1, na_idx, 0+0i))
test(2060.601, fcoalesce(z1, z2), `[<-`(z1, na_idx, c(4-2i, NA, NA)))
Expand Down Expand Up @@ -15509,7 +15509,7 @@ z = c(1:3) + c(3:1)*1i
test(2067.1, shift(z), c(NA, z[1:2]))
test(2067.2, shift(z, type = 'lead'), c(z[2:3], NA))
test(2067.3, shift(z, fill = 1i), c(1i, z[1:2]))
test(2067.4, shift(list(z, 1:3)), list(c(NA, z[1:2]), c(NA, 1:2)))
test(2067.4, shift(list(z, 1:3)), list(c(NA_complex_, z[1:2]), c(NA, 1:2)))
test(2067.5, shift(z, n=1, type = 'cyclic'), c(z[3], z[1:2]))
test(2067.6, shift(z, n=-1, type = 'cyclic'), c(z[2:3], z[1]))
test(2067.7, shift(list(z, 1L:3L), n=1, type = 'cyclic'), list(c(z[3], z[1:2]), c(3L, 1:2)))
Expand Down
Loading