You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/01/11 16:27:00 UTC

[GitHub] [arrow] nealrichardson commented on a change in pull request #9118: ARROW-10623: [CI][R] Version 1.0.1 breaks data.frame attributes when reading file written by 2.0.0

nealrichardson commented on a change in pull request #9118:
URL: https://github.com/apache/arrow/pull/9118#discussion_r555174313



##########
File path: r/tests/testthat/test-backwards-compatibility.R
##########
@@ -0,0 +1,166 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# To write a new version of a test file for a current version:
+# write_parquet(example_with_metadata, test_path("golden-files/data-arrow_2.0.0.parquet"))
+
+# To write a new version of a test file for an old version, use docker(-compose)
+# to setup a linux distribution and use RStudio's public package manager binary
+# repo to install the old version. The following commands should be run at the
+# root of the arrow repo directory and might need slight adjusments.
+# R_ORG=rstudio R_IMAGE=r-base R_TAG=4.0-focal docker-compose build --no-cache r
+# R_ORG=rstudio R_IMAGE=r-base R_TAG=4.0-focal docker-compose run r /bin/bash
+# R
+# options(repos = "https://packagemanager.rstudio.com/all/__linux__/focal/latest")
+# remotes::install_version("arrow", version = "1.0.1")
+# # get example data into the global env
+# write_parquet(example_with_metadata, "arrow/r/tests/testthat/golden-files/data-arrow_1.0.1.parquet")
+# quit()/exit
+
+test_that("reading a known Parquet file to dataframe with 2.0.0", {
+  skip_if_not_available("snappy")
+  pq_file <- test_path("golden-files/data-arrow_2.0.0.parquet")
+
+  df <- read_parquet(pq_file)
+  expect_equal(df, example_with_metadata)
+  expect_identical(dim(df), c(1L, 4L))
+
+  expect_equal(
+    attributes(df),
+    list(
+      names = letters[1:4],
+      row.names = 1L,
+      top_level = list(field_one = 12, field_two = "more stuff"),
+      class = c("tbl_df", "tbl", "data.frame"))
+  )
+  expect_equal(attributes(df$a), list(class = "special_string"))
+  expect_null(attributes(df$b))
+  expect_equal(
+    attributes(df$c),
+    list(
+      row.names = 1L,
+      names = c("c1", "c2", "c3"),
+      class = c("tbl_df", "tbl", "data.frame")
+    )
+  )
+  expect_null(attributes(df$d))
+})
+
+test_that("reading a known Parquet file to dataframe with 1.0.1", {
+  skip_if_not_available("snappy")
+  pq_file <- test_path("golden-files/data-arrow_1.0.1.parquet")
+
+  df <- read_parquet(pq_file)
+  # 1.0.1 didn't save top-level metadata, so we need to remove it.
+  example_with_metadata_sans_toplevel <- example_with_metadata
+  attributes(example_with_metadata_sans_toplevel)$top_level <- NULL
+  expect_equal(df, example_with_metadata_sans_toplevel)

Review comment:
       why not just `expect_identical` and skip the rest of the assertions?

##########
File path: r/extra-tests/test-read-files.R
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+library(arrow)
+library(testthat)
+
+pq_file <- "files/ex_data.parquet"
+
+test_that("Can read the file (parquet)", {
+  # We can read with no error, we assert metadata below
+  expect_error(
+    df <- read_parquet(pq_file),
+    NA
+  )
+})
+
+### Parquet
+test_that("Can see the metadata (parquet)", {
+  skip_if_version_less_than("2.0.0", "Version 1.0.1 can't read new version metadata.")
+
+  df <- read_parquet(pq_file)
+  expect_s3_class(df, "tbl")
+
+  expect_equal(
+    attributes(df),
+    list(
+      names = letters[1:4],
+      row.names = 1L,
+      top_level = list(
+        field_one = 12,
+        field_two = "more stuff"
+      ),
+      class = c("tbl_df", "tbl", "data.frame")
+    )
+  )
+
+  # column-level attributes
+  expect_equal(attributes(df$a), list(class = "special_string"))
+  expect_equal(
+    attributes(df$c),
+    list(
+      row.names = 1L,
+      names = c("c1", "c2", "c3"),
+      class = c("tbl_df", "tbl", "data.frame")
+    )
+  )
+})

Review comment:
       What do you think about factoring this out to an `expect_something()` helper in this file, such that your tests here are just `expect_something(df)`?
   
   Of course, the simplest one would be `expect_identical(df, example_with_metadata)`, right? Though there are tradeoffs with that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org