Skip to content

Commit 7284501

Browse files
Revert "Add warning when index variable is implicitly retained"
This reverts commit 2ff1e36.
1 parent 19883ed commit 7284501

4 files changed

Lines changed: 8 additions & 46 deletions

File tree

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Fixed `scan_gaps()` failing with data containing the `int` column name.
44
* Removed `as_tibble.grouped_df()` to prevent masking `dplyr::as_tibble.grouped_df()`.
55
* Added `summary()` method for time classes, allowing `summary()` to be called on tsibble objects. (#319)
6-
* `select()` and `transmute()` now warn when the index variable is dropped and automatically re-added.
76
* `tsibble()` now builds columns sequentially, allowing columns to refer to previously created columns in the call. (#289)
87
* Add tidyselect helpers for `index_var()`, `key_vars()` and `measured_vars()`. (#314)
98
* Documentation improvements.

R/update.R

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ bind_tsibble <- function(data, template, position = c("before", "after")) {
8181
template <- remove_key(template, setdiff(key_vars(template), key_vars))
8282
}
8383
tsbl_vars <- setdiff(c(index_var(template), key_vars(template)), data_cols)
84-
85-
# Warn if index variable was dropped
86-
idx_var <- index_var(template)
87-
if (idx_var %in% tsbl_vars) {
88-
warn(sprintf(
89-
"Index variable `%s` was dropped but has been automatically re-added.\nUse `as_tibble()` first if you want to remove the index.",
90-
idx_var
91-
))
92-
}
93-
9484
if (position == "before") {
9585
res <- bind_cols(as_tibble(template)[tsbl_vars], data)
9686
} else {

tests/testthat/test-dplyr.R

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ test_that("filter() and slice() with .preserve = TRUE", {
149149
})
150150

151151
test_that("select() and rename()", {
152-
expect_s3_class(select(tourism, Quarter, Region:Purpose), "tbl_ts")
152+
expect_s3_class(select(tourism, Region:Purpose), "tbl_ts")
153153
expect_s3_class(select(tourism, Quarter:Purpose), "tbl_ts")
154154
expect_equal(
155155
quo_name(index(select(tourism, Index = Quarter, Region:Purpose))),
@@ -166,7 +166,7 @@ test_that("select() and rename()", {
166166
expect_named(select(tourism_mel, -Region), cols[-2])
167167
expect_named(select(tourism_mel, -State), cols[-3])
168168
expect_named(select(tourism_mel, -Purpose), cols[-4])
169-
expect_named(select(tourism_mel, Quarter, Trips), c("Quarter", "Trips"))
169+
expect_named(select(tourism_mel, Trips), c("Trips", "Quarter"))
170170
expect_named(select(tourism_mel, -Region, -State, -Purpose), cols[c(1, 5)])
171171
})
172172

@@ -254,21 +254,21 @@ tsbl <- tsibble(
254254
)
255255

256256
test_that("transmute()", {
257-
out <- tourism %>% transmute(Quarter, Region = paste(Region, State))
257+
out <- tourism %>% transmute(Region = paste(Region, State))
258258
expect_equal(ncol(out), 4)
259-
trans_tsbl <- tsbl %>% transmute(qtr, group, z = a / b)
259+
trans_tsbl <- tsbl %>% transmute(z = a / b)
260260
expect_equal(colnames(trans_tsbl), c("qtr", "group", "z"))
261261
})
262262

263263
test_that("transmute.grouped_ts()", {
264264
out <- pedestrian %>%
265265
group_by(Time) %>%
266-
transmute(Date_Time)
266+
transmute()
267267
expect_equal(ncol(out), 3)
268268
out2 <- pedestrian %>%
269269
group_by_key() %>%
270-
transmute(Date_Time)
271-
expect_named(out2, c("Sensor", "Date_Time"))
270+
transmute()
271+
expect_named(out2, c("Date_Time", "Sensor"))
272272
})
273273

274274
test_that("distinct()", {
@@ -355,33 +355,6 @@ test_that("rename() for renaming key", {
355355
rename("purpose" = "Purpose", "region" = "Region", "trip" = "Trips")
356356
})
357357

358-
test_that("warning when index is automatically re-added #308", {
359-
test_ts <- tsibble(
360-
date = as.Date('2024-01-01') + 0:2,
361-
value = 1:3
362-
)
363-
364-
# select() without index should warn
365-
expect_warning(
366-
result <- select(test_ts, value),
367-
"Index variable `date` was dropped"
368-
)
369-
expect_true("date" %in% names(result))
370-
371-
# transmute() without index should warn
372-
expect_warning(
373-
result2 <- transmute(test_ts, value2 = value * 2),
374-
"Index variable `date` was dropped"
375-
)
376-
expect_true("date" %in% names(result2))
377-
378-
# select() with index should not warn
379-
expect_no_warning(
380-
result3 <- select(test_ts, date, value)
381-
)
382-
expect_equal(names(result3), c("date", "value"))
383-
})
384-
385358
test_that("drop redundant key #196", {
386359
sim_tourism <- tourism %>%
387360
filter(Purpose == "Holiday") %>%

tests/testthat/test-empty.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("dplyr verbs for empty tsibble", {
1313
expect_equal(NROW(ped_null), 0L)
1414
expect_s3_class(ped_null %>% group_by(Sensor), "grouped_ts")
1515
expect_equal(NROW(ped_null %>% mutate(Count1 = Count + 1)), 0L)
16-
expect_equal(NROW(ped_null %>% transmute(Date_Time, Count1 = Count + 1)), 0L)
16+
expect_equal(NROW(ped_null %>% transmute(Count1 = Count + 1)), 0L)
1717
expect_equal(NROW(ped_null %>% summarise(Count1 = sum(Count))), 0L)
1818
expect_identical(ped_null %>% arrange(Count), ped_null)
1919
expect_identical(ped_null %>% slice(0), ped_null)

0 commit comments

Comments
 (0)