Skip to content

Commit

Permalink
Update tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jul 11, 2023
1 parent 07c0fb3 commit 9f33658
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 138 deletions.
4 changes: 2 additions & 2 deletions inst/tinytest/test_arrowio.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tiledb_query_set_layout(qry, "UNORDERED")
tiledb_query_submit(qry)
tiledb_query_finalize(qry)

#arr <- tiledb_array(tmp, as.data.frame=TRUE)
#arr <- tiledb_array(tmp, return_as="data.frame")
#print(arr[])


Expand Down Expand Up @@ -162,7 +162,7 @@ tiledb_query_set_layout(qry, "UNORDERED")
tiledb_query_submit(qry)
tiledb_query_finalize(qry)

arr <- tiledb_array(tmp, as.data.frame=TRUE)
arr <- tiledb_array(tmp, return_as="data.frame")
df <- arr[]

for (i in 1:10) {
Expand Down
6 changes: 3 additions & 3 deletions inst/tinytest/test_attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ attrib <- c(tiledb_attr("year", type = "DATETIME_YEAR"), # year
schema <- tiledb_array_schema(domain, attrib, sparse=TRUE)
res <- tiledb_array_create(uri, schema)

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")

dvec <- 1:3
data <- data.frame(row = dvec,
Expand All @@ -162,7 +162,7 @@ data <- data.frame(row = dvec,
)

arr[] <- data
arr2 <- tiledb_array(uri, as.data.frame=TRUE)
arr2 <- tiledb_array(uri, return_as="data.frame")
readdata <- arr2[]
expect_true(all.equal(data, readdata, check.attributes=FALSE))

Expand Down Expand Up @@ -217,7 +217,7 @@ df <- data.frame(row = 1:10,
arr <- tiledb_array(uri)
arr[] <- df

newarr <- tiledb_array(uri, as.data.frame=TRUE)
newarr <- tiledb_array(uri, return_as="data.frame")
chk <- newarr[]
expect_equal(df[,1:10], chk[,1:10])
expect_equivalent(as.numeric(df[,11]), chk[,11]) # we currently return uint64_t as numeric
Expand Down
36 changes: 18 additions & 18 deletions inst/tinytest/test_dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (tiledb_version(TRUE) < "2.7.0") exit_file("Needs TileDB 2.7.* or later")

fromDataFrame(irisdf, uri)

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
newdf <- arr[]
#if (getRversion() >= '4.0.0') newdf$Species <- as.factor(newdf$Species)
if (getRversion() < '4.0.0') newdf$Species <- as.character(newdf$Species)
Expand All @@ -29,7 +29,7 @@ expect_equal(irisdf, newdf[,-1])


## test attrs subselection
arr <- tiledb_array(uri, as.data.frame=TRUE, extended=FALSE,
arr <- tiledb_array(uri, return_as="data.frame", extended=FALSE,
attrs = c("Petal.Length", "Petal.Width"))
newdf <- arr[]
expect_equivalent(iris[, c("Petal.Length", "Petal.Width")], newdf) # skip attribute
Expand Down Expand Up @@ -58,7 +58,7 @@ df <- data.frame(char=c("abc", "def", "g", "hijk"),

fromDataFrame(df, uri)

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
newdf <- arr[]

## result comes back as factor by default
Expand All @@ -78,7 +78,7 @@ df <- data.frame(index=sort(sample(1:1000, rows)),
vals=rnorm(rows) * 100,
stringsAsFactors=FALSE)
fromDataFrame(df, uri)
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$chars <- as.character(chk$chars)
expect_equal(df, chk[,-1]) # omit first col which is added
Expand All @@ -87,7 +87,7 @@ if (tiledb_version(TRUE) < "2.1.0") exit_file("Remaining tests require TileDB 2.

if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, col_index=1)
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$chars <- as.character(chk$chars)
expect_equal(df[,2], na.omit(chk)[,2]) # compare column by column
Expand All @@ -96,7 +96,7 @@ expect_equal(df[,3], na.omit(chk)[,3])

if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, col_index="index")
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$chars <- as.character(chk$chars)
expect_equal(df[,2], na.omit(chk)[,2]) # compare column by column
Expand All @@ -108,7 +108,7 @@ df <- data.frame(chars=olddf$chars,
val=olddf$vals)
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri)
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') {
df$chars <- as.character(df$chars)
Expand All @@ -118,15 +118,15 @@ expect_equal(df, chk[,-1]) # omit first col which is added

if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, col_index=2)
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$chars <- as.character(chk$chars)
expect_equal(df[,1], na.omit(chk)[,2]) # compare column by column
expect_equal(df[,3], na.omit(chk)[,3])

if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, col_index="index")
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$chars <- as.character(chk$chars)
expect_equal(df[,1], na.omit(chk)[,2]) # compare column by column
Expand Down Expand Up @@ -155,13 +155,13 @@ df <- data.frame(time=round(Sys.time(), "secs") + trunc(cumsum(runif(nobs)*3600)
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE)

chk <- tiledb_array(uri, as.data.frame=TRUE, extended=FALSE)
chk <- tiledb_array(uri, return_as="data.frame", extended=FALSE)
expect_equivalent(df, chk[]) # skip attribute

for (i in seq_len(dim(df)[2])) {
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE, col_index=i)
chk <- tiledb_array(uri, as.data.frame=TRUE)
chk <- tiledb_array(uri, return_as="data.frame")
expect_equal(df, chk[][,colnames(df)]) # index col comes first so need re-order
}

Expand All @@ -181,7 +181,7 @@ df <- data.frame(time = round(Sys.time(), "secs") + trunc(cumsum(runif(nobs)*360
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE)

chk <- tiledb_array(uri, as.data.frame=TRUE, extended=FALSE)
chk <- tiledb_array(uri, return_as="data.frame", extended=FALSE)
newdf <- chk[]
if (getRversion() < '4.0.0') newdf$txt <- as.character(newdf$txt)
expect_equivalent(df, newdf) # skip attribute
Expand All @@ -190,7 +190,7 @@ expect_equivalent(df, newdf) # skip attribute
for (i in seq_len(dim(df)[2])) {
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE, col_index=i)
chk <- tiledb_array(uri, as.data.frame=TRUE)
chk <- tiledb_array(uri, return_as="data.frame")
newdf <- chk[]
if (getRversion() < '4.0.0') newdf$txt <- as.character(newdf$txt)
expect_equal(df, newdf[, colnames(df)])
Expand All @@ -201,14 +201,14 @@ combinations <- list(c(1,2), c(1,3), c(2,4), c(3,5), c(4,5), c(2,3,4))
for (comb in combinations) {
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE, col_index=comb) # by index
chk <- tiledb_array(uri, as.data.frame=TRUE)
chk <- tiledb_array(uri, return_as="data.frame")
newdf <- chk[]
if (getRversion() < '4.0.0') newdf$txt <- as.character(newdf$txt)
expect_equal(df, newdf[][, colnames(df)])

if (dir.exists(uri)) unlink(uri, recursive=TRUE)
fromDataFrame(df, uri, sparse=TRUE, col_index=colnames(df)[comb]) # by name
chk <- tiledb_array(uri, as.data.frame=TRUE)
chk <- tiledb_array(uri, return_as="data.frame")
newdf <- chk[]
if (getRversion() < '4.0.0') newdf$txt <- as.character(newdf$txt)
expect_equal(df, newdf[, colnames(df)])
Expand All @@ -223,7 +223,7 @@ dat <- data.frame(A=1:10,
dat[3,1] <- NA
dat[4,3] <- NA
fromDataFrame(dat, uri)
chk <- tiledb_array(uri, as.data.frame=TRUE)
chk <- tiledb_array(uri, return_as="data.frame")
val <- chk[][,-1] # omit added rows
if (getRversion() < '4.0.0') {
dat$B <- as.character(dat$B)
Expand All @@ -239,7 +239,7 @@ D <- data.frame(sample=paste(LETTERS[1:N], as.character(sort(trunc(runif(N, 100,
stringsAsFactors=FALSE)
uri <- tempfile()
fromDataFrame(D, uri, col_index=1, sparse=TRUE)
arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') {
chk$sample <- as.character(chk$sample)
Expand All @@ -260,7 +260,7 @@ expect_error(fromDataFrame(df, uri, col_index=1, sparse=TRUE, allows_dups=FALSE)
uri <- tempfile()
expect_silent(arr <- fromDataFrame(df, uri, col_index=1, sparse=TRUE, allows_dups=TRUE))

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
chk <- arr[]
if (getRversion() < '4.0.0') chk$char <- as.character(chk$char)
expect_equivalent(df, chk) # skip attribute
Expand Down
12 changes: 6 additions & 6 deletions inst/tinytest/test_dim.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ for (dtype in dimtypes) {
schema <- tiledb_array_schema(domain, attrib, sparse=TRUE)
tiledb_array_create(uri, schema)

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
dvec <- switch(dtype,
"ASCII" = LETTERS[1:5],
"INT8" =,
Expand Down Expand Up @@ -195,7 +195,7 @@ for (dtype in dimtypes) {
data <- data.frame(row = dvec, attr = avec, stringsAsFactors=FALSE)
arr[] <- data

arr2 <- tiledb_array(uri, as.data.frame=TRUE)
arr2 <- tiledb_array(uri, return_as="data.frame")
readdata <- arr2[]
if (dtype == "ASCII" && getRversion() < '4.0.0') readdata$row <- as.character(readdata$row)
if (dtype == "UINT64") readdata[,1] <- as.integer64(readdata[,1]) # return doubles here
Expand All @@ -212,7 +212,7 @@ for (dtype in dimtypes) {
}

## subset tests
arr3 <- tiledb_array(uri, as.data.frame=TRUE)
arr3 <- tiledb_array(uri, return_as="data.frame")
if (dtype %in% c("DATETIME_YEAR", "DATETIME_MONTH", "DATETIME_WEEK", "DATETIME_DAY")) {
scaleDate <- function(val, dtype) {
val <- switch(dtype,
Expand Down Expand Up @@ -331,7 +331,7 @@ for (dtype in dimtypes) {
schema <- tiledb_array_schema(domain, attrib, sparse=TRUE)
tiledb_array_create(uri, schema)

arr <- tiledb_array(uri, as.data.frame=TRUE)
arr <- tiledb_array(uri, return_as="data.frame")
dvec <- switch(dtype,
"ASCII" = LETTERS[1:5],
"INT8" =,
Expand Down Expand Up @@ -363,7 +363,7 @@ for (dtype in dimtypes) {
data <- data.frame(row = dvec, attr = avec, stringsAsFactors=FALSE)
arr[] <- data

## arr2 <- tiledb_array(uri, as.data.frame=TRUE)
## arr2 <- tiledb_array(uri, return_as="data.frame")
## readdata <- arr2[]
## if (dtype == "ASCII" && getRversion() < '4.0.0') readdata$row <- as.character(readdata$row)
## if (dtype == "UINT64") readdata[,1] <- as.integer64(readdata[,1]) # return doubles here
Expand All @@ -380,7 +380,7 @@ for (dtype in dimtypes) {
## }

## subset tests
arr3 <- tiledb_array(uri, as.data.frame=TRUE)
arr3 <- tiledb_array(uri, return_as="data.frame")
if (dtype %in% c("DATETIME_YEAR", "DATETIME_MONTH", "DATETIME_WEEK", "DATETIME_DAY")) {
scaleDate <- function(val, dtype) {
val <- switch(dtype,
Expand Down
6 changes: 3 additions & 3 deletions inst/tinytest/test_dimsubset.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ log_info("re-arranged list object made")
arr[] <- newlst
log_info("array written")

newarr <- tiledb_array(tmp, as.data.frame=TRUE, query_layout="UNORDERED")
newarr <- tiledb_array(tmp, return_as="data.frame", query_layout="UNORDERED")
dat <- newarr[]
log_info("array read")
expect_equal(nrow(dat), nrow(flights))
Expand All @@ -97,15 +97,15 @@ expect_equal(unique(dat$origin), "JFK")
expect_equal(unique(dat$dest), "BOS")

## same via selected_points
newarr <- tiledb_array(tmp, as.data.frame=TRUE, query_layout="UNORDERED",
newarr <- tiledb_array(tmp, return_as="data.frame", query_layout="UNORDERED",
selected_points= list("AA", "JFK", "BOS", NULL))
dat <- newarr[]
expect_equal(unique(dat$carrier), "AA")
expect_equal(unique(dat$origin), "JFK")
expect_equal(unique(dat$dest), "BOS")

## test named lists with one element
newarr <- tiledb_array(tmp, as.data.frame=TRUE, query_layout="UNORDERED")
newarr <- tiledb_array(tmp, return_as="data.frame", query_layout="UNORDERED")
selected_ranges(newarr) <- list(carrier = cbind("AA","AA"))
dat <- newarr[]
expect_equal(unique(dat$carrier), "AA")
Expand Down
6 changes: 2 additions & 4 deletions inst/tinytest/test_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ unlink_and_create_simple <- function(tmp) {
sch <- tiledb_array_schema(dom, c(a1, a2), sparse=TRUE)
tiledb_array_create(tmp, sch)

#arr <- tiledb_sparse(tmp, as.data.frame=FALSE)
arr <- tiledb_array(tmp, as.data.frame=FALSE)
arr <- tiledb_array(tmp, return_as="asis")

if (tiledb:::libtiledb_array_is_open(arr@ptr)) {
tiledb_array_close(arr)
Expand All @@ -44,8 +43,7 @@ unlink_and_create_ptr <- function(tmp) {

arr <- tiledb_array_open(arr, "READ")
##return(arrR)
#arr <- tiledb_sparse(tmp, as.data.frame=FALSE)
arr <- tiledb_array(tmp, as.data.frame=FALSE)
arr <- tiledb_array(tmp, return_as="asis")
}

close_and_reopen <- function(arr, txt) {
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ cfg <- tiledb_config()
cfg["sm.memory_budget"] <- "16"
cfg["sm.memory_budget_var"] <- "32"
ctx <- tiledb_ctx(cfg)
array <- tiledb_array(tmp, as.data.frame=TRUE)
array <- tiledb_array(tmp, return_as="data.frame")

if (packageVersion("tiledb") <= "0.11.0") expect_warning(res <- array[]) # newer versions loop, no warning

Expand Down
Loading

0 comments on commit 9f33658

Please sign in to comment.