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

Old fastf1 deprecate Warn #202

Merged
merged 6 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion R/clear_f1_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ clear_f1_cache <- function() {
if (reticulate::py_available(initialize = TRUE)) {
if ("fastf1" %in% reticulate::py_list_packages()$package) {
reticulate::py_run_string("import fastf1")
if (get_fastf1_version() >= 3) {
if (get_fastf1_version()$major >= 3) {
try(
reticulate::py_run_string(glue::glue("fastf1.Cache.clear_cache('{cache_dir}')",
cache_dir = normalizePath(getOption("f1dataR.cache"))
Expand Down
4 changes: 2 additions & 2 deletions R/load_driver_telemetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess
# Param checks
if (!(laps %in% c("fastest", "all"))) {
if (is.numeric(laps)) {
if (get_fastf1_version() < 3) {
if (get_fastf1_version()$major < 3) {
cli::cli_abort("{.var laps} can only be a lap number if using fastf1 v3.0 or higher")
}
if (as.numeric(laps) != as.integer(laps)) {
Expand All @@ -80,7 +80,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess
}
)

if (get_fastf1_version() < 3) {
if (get_fastf1_version()$major < 3) {
add_v3_option <- ""
} else {
add_v3_option <- ".add_driver_ahead()"
Expand Down
2 changes: 1 addition & 1 deletion R/load_race_session.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ load_race_session <- function(obj_name = "session", season = get_current_season(
}

reticulate::py_run_string("import fastf1")
if (get_fastf1_version() >= 3) {
if (get_fastf1_version()$major >= 3) {
reticulate::py_run_string(glue::glue("fastf1.set_log_level('{log_level}')", log_level = log_level))
}

Expand Down
6 changes: 3 additions & 3 deletions R/load_session_laps.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session
round <- race
}

if (get_fastf1_version() < 3) {
if (get_fastf1_version()$major < 3) {
cli::cli_alert_warning("An old version of FastF1 is in use. Additional data is provided if using FastF1 v3.0.0 or later.")
}

Expand Down Expand Up @@ -60,7 +60,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session
))
}

if (session == "Q" && get_fastf1_version() >= 3) {
if (session == "Q" && get_fastf1_version()$major >= 3) {
# prepping for Q1/Q2/Q3 labels - this has to happen before timedelta64 is converted to seconds
reticulate::py_run_string(paste("q1, q2, q3 = laps.split_qualifying_sessions()",
"q1len = len(q1.index)",
Expand Down Expand Up @@ -91,7 +91,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session
laps <- laps %>%
dplyr::mutate("Time" = .data$Time)

if (session == "Q" && get_fastf1_version() >= 3) {
if (session == "Q" && get_fastf1_version()$major >= 3) {
# pull the lengths of each Quali session from the python env.
q1len <- reticulate::py_to_r(reticulate::py_get_item(py_env, "q1len"))
q2len <- reticulate::py_to_r(reticulate::py_get_item(py_env, "q2len"))
Expand Down
14 changes: 8 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ get_fastf1_version <- function() {
cli::cli_warn("Ensure {.pkg fastf1} Python package is installed.\nPlease run this to install the most recent version:\n{.code setup_fastf1()}")
return(NA)
}
if (as.integer(substr(ver, start = 1, 1)) >= 3) {
return(3)
} else if (as.integer(substr(ver, start = 1, 1)) <= 2) {
major <- as.integer(unlist(strsplit(ver, ".", fixed = T))[1])
minor <- as.integer(unlist(strsplit(ver, ".", fixed = T))[2])
if (major < 3 | (major == 3 & minor < 1)) {
lifecycle::deprecate_warn("1.4.1",
what = I("fastf1 version < 3.1"), with = I("fastf1 version >= 3.1"),
details = c("Hard deprecation will occur between 2023 and 2024 F1 seasons")
)
cli::cli_inform("The Python package {.pgk fastf1} was updated to v3 recently.\nPlease update the version on your system by running:\n{.code setup_fastf1(newenv = TRUE)}\nFuture versions of {.pkg f1dataR} may not support {.pkg fastf1<3.0.0}.")
return(2)
} else {
return(NA)
}
return(list(major = major, minor = minor))
}

# nocov start
Expand Down
Binary file added tests/testthat/Rplots.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-load_driver_telemetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_that("driver telemetry", {

expect_true(nrow(telem) > nrow(telem_fast))
expect_true(ncol(telem) == ncol(telem_fast))
if (get_fastf1_version() >= 3) {
if (get_fastf1_version()$major >= 3) {
expect_equal(telem_fast$session_time[[1]], 3518.641)
expect_equal(telem_fast$time[[2]], 0.086)
} # else {
Expand All @@ -30,7 +30,7 @@ test_that("driver telemetry", {
# "can only be a lap number if using fastf1 v3.0 or higher"
# )
# }
if (get_fastf1_version() >= 3) {
if (get_fastf1_version()$major >= 3) {
telem_lap <- load_driver_telemetry(season = 2022, round = "Brazil", session = "S", driver = "HAM", laps = 1)
expect_equal(telem_lap$time[[1]], 0)
expect_equal(telem_lap$speed[[1]], 0)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-load_session_laps.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("load session laps works", {
expect_equal(laps$time, laps2$time)
expect_true(!is.na(laps$time[1]))
expect_equal(nrow(laps), nrow(laps2))
if (get_fastf1_version() >= 3) {
if (get_fastf1_version()$major >= 3) {
expect_true(all(lapsq$session_type %in% c("Q1", "Q2", "Q3")))
expect_true(all(c("Q1", "Q2", "Q3") %in% unique(lapsq$session_type)))
}
Expand Down
2 changes: 1 addition & 1 deletion vignettes/setup_fastf1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ the Python package [`FastF1`](https://docs.fastf1.dev/). This guide may help res
that might arise when you get the following warning or error messages:

- `Ensure fastf1 python package is installed. Please run this to install the most recent version: setup_fastf1()`
- `Error in if (get_fastf1_version() < 3) { :`
- `Error in if (get_fastf1_version()$major < 3) { :`
`missing value where TRUE/FALSE needed`

If these happen to you (particularly if you're a new user of `f1dataR`) read on!
Expand Down