22test_that(" double should not be altered" , {
33 x <- data.frame (a = runif(1000 , min = - 1 , max = 1 ))
44
5- expect_equal(x , from_r_data(x ))
5+ expect_equal(x , from_r_data(x , factors_as_strings = FALSE ))
66
77 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
88
9- expect_equal(from_r_data(x ), x )
9+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x )
1010})
1111
1212test_that(" integer should become a double" , {
1313 x <- data.frame (a = sample(- 1000 : 1000 , 1000 , replace = TRUE ))
1414 x_expected <- x
1515 x_expected $ a <- as.double(x_expected $ a )
1616
17- expect_equal(from_r_data(x ), x_expected )
17+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
1818
1919 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
2020 x_expected <- x
2121 x_expected $ a <- as.double(x_expected $ a )
2222
23- expect_equal(from_r_data(x ), x_expected )
23+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
2424})
2525
2626test_that(" logical should become a double" , {
2727 x <- data.frame (a = sample(c(TRUE , FALSE ), 1000 , replace = TRUE ))
2828 x_expected <- x
2929 x_expected $ a <- as.double(x_expected $ a )
3030
31- expect_equal(from_r_data(x ), x_expected )
31+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
3232
3333 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
3434 x_expected <- x
3535 x_expected $ a <- as.double(x_expected $ a )
3636
37- expect_equal(from_r_data(x ), x_expected )
37+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
3838})
3939
4040test_that(" character should not be altered" , {
4141 x <- data.frame (
4242 a = sample(c(" apple" , " pear" , " orange" , " cherry" ), 1000 , replace = TRUE )
4343 )
4444
45- expect_equal(from_r_data(x ), x )
45+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x )
4646
4747 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
4848
49- expect_equal(from_r_data(x ), x )
49+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x )
5050})
5151
52- test_that(" factor should become a character" , {
52+ test_that(" factor as character" , {
5353 x <- data.frame (
5454 a = as.factor(sample(
5555 c(" apple" , " pear" , " orange" , " cherry" ),
@@ -60,13 +60,33 @@ test_that("factor should become a character", {
6060 x_expected <- x
6161 x_expected $ a <- as.character(x_expected $ a )
6262
63- expect_equal(from_r_data(x ), x_expected )
63+ expect_equal(from_r_data(x , factors_as_strings = TRUE ), x_expected )
6464
6565 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
6666 x_expected <- x
6767 x_expected $ a <- as.character(x_expected $ a )
6868
69- expect_equal(from_r_data(x ), x_expected )
69+ expect_equal(from_r_data(x , factors_as_strings = TRUE ), x_expected )
70+ })
71+
72+ test_that(" factor as format (numeric)" , {
73+ x <- data.frame (
74+ a = as.factor(sample(
75+ c(" apple" , " pear" , " orange" , " cherry" ),
76+ 1000 ,
77+ replace = TRUE
78+ ))
79+ )
80+ x_expected <- x
81+ x_expected $ a <- as.numeric(x_expected $ a )
82+
83+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
84+
85+ x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
86+ x_expected <- x
87+ x_expected $ a <- as.numeric(x_expected $ a )
88+
89+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
7090})
7191
7292test_that(" POSIXct should be converted to UTC" , {
@@ -78,13 +98,13 @@ test_that("POSIXct should be converted to UTC", {
7898 x_expected <- x
7999 x_expected $ a <- as.POSIXct(format(x_expected $ a ), tz = " UTC" )
80100
81- expect_equal(from_r_data(x ), x_expected )
101+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
82102
83103 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
84104 x_expected <- x
85105 x_expected $ a <- as.POSIXct(format(x_expected $ a ), tz = " UTC" )
86106
87- expect_equal(from_r_data(x ), x_expected )
107+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
88108})
89109
90110test_that(" date should become a POSIXct" , {
@@ -94,13 +114,13 @@ test_that("date should become a POSIXct", {
94114 x_expected <- x
95115 x_expected $ a <- as.POSIXct(x_expected $ a )
96116
97- expect_equal(from_r_data(x ), x_expected )
117+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
98118
99119 x $ a [sample(seq_len(nrow(x )), 100 )] <- NA
100120 x_expected <- x
101121 x_expected $ a <- as.POSIXct(x_expected $ a )
102122
103- expect_equal(from_r_data(x ), x_expected )
123+ expect_equal(from_r_data(x , factors_as_strings = FALSE ), x_expected )
104124})
105125
106126test_that(" date should be added to date dict" , {
@@ -114,7 +134,7 @@ test_that("date should be added to date dict", {
114134 )
115135
116136 expect_equal(
117- from_r_datetypes( x ),
137+ reticulate :: py_to_r(from_r_datedict( x ) ),
118138 date_dict_expected
119139 )
120140})
0 commit comments