Skip to content

Commit

Permalink
Added test for timegpt_forecast function.
Browse files Browse the repository at this point in the history
  • Loading branch information
MMenchero committed Dec 27, 2023
1 parent f93b64e commit 2a38e20
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: nixtlar
Title: R SDK For Nixtla's TimeGPT
Version: 0.0.0.9000
Version: 1.0.0
Authors@R:
person("Mariana", "Menchero", , "[email protected]", role = c("aut", "cre"))
Description: An SDK to interface with Nixtla's TimeGPT from R.
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(.get_token)
export(.timegpt_data_prep)
export(.validate_exogenous)
export(date_conversion)
export(infer_frequency)
Expand Down
4 changes: 3 additions & 1 deletion R/get_token.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Get TIMEGPT_TOKEN from options or from .Renviron
#' This is a private function of the package
#' This is a private function of nixtlar
#'
#' @return If available, the TIMEGTP_TOKEN
#' @export
#' @keywords internal
#'
.get_token <- function(){

Expand Down
2 changes: 2 additions & 0 deletions R/timegpt_data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param target_col Column that contains the target variable. Should be named y.
#'
#' @return A list with the given or inferred frequency, the prepared data, and the original data frame renamed.
#' @export
#' @keywords internal
#'
.timegpt_data_prep <- function(df, freq, id_col, time_col, target_col){

Expand Down
1 change: 1 addition & 0 deletions R/validate_exogenous.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' @return A list with the result of the validation (TRUE/FALSE) and an error message (if applicable)
#' @export
#' @keywords internal
#'
.validate_exogenous <- function(df, h, X_df){

Expand Down
15 changes: 15 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
url: https://mmenchero.github.io/nixtlar/
template:
bootstrap: 5
params:
github:
repo: mmenchero/nixtlar

navbar:
title: "nixtlar"
left:
- text: "Home"
href: index.html
- text: "Get Started"
href: articles/get-started.html
- text: "Reference"
href: reference/index.html
- text: "Articles"
menu:
- text: "Anomaly Detection"
5 changes: 3 additions & 2 deletions man/dot-get_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dot-timegpt_data_prep.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dot-validate_exogenous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions tests/testthat/dashboard.nixtla.io/api/timegpt.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[
"BE",
"2016-12-31 01:00:00",
42.426597595214844
42.42660140991211
],
[
"BE",
Expand Down Expand Up @@ -55,7 +55,7 @@
[
"DE",
"2017-12-31 01:00:00",
-2.9869346618652344
-2.9869308471679688
],
[
"DE",
Expand Down Expand Up @@ -85,12 +85,12 @@
[
"DE",
"2017-12-31 07:00:00",
-0.4271507263183594
-0.427154541015625
],
[
"FR",
"2016-12-31 00:00:00",
62.130218505859375
62.130226135253906
],
[
"FR",
Expand All @@ -110,12 +110,12 @@
[
"FR",
"2016-12-31 04:00:00",
46.49836730957031
46.49835968017578
],
[
"FR",
"2016-12-31 05:00:00",
49.270904541015625
49.270896911621094
],
[
"FR",
Expand Down Expand Up @@ -160,7 +160,7 @@
[
"NP",
"2018-12-24 06:00:00",
52.23451614379883
52.234519958496094
],
[
"NP",
Expand All @@ -180,12 +180,12 @@
[
"PJM",
"2018-12-24 02:00:00",
20.667823791503906
20.667821884155273
],
[
"PJM",
"2018-12-24 03:00:00",
20.97324562072754
20.973247528076172
],
[
"PJM",
Expand Down Expand Up @@ -216,6 +216,6 @@
"message": "success",
"details": "request successful",
"code": "B10",
"requestID": "6K8VVPHJMH",
"requestID": "X2KW6WKKEP",
"support": "If you have questions or need support, please email [email protected]"
}
6 changes: 3 additions & 3 deletions tests/testthat/test-timegpt_forecast.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
with_mock_dir("timegpt_forecast", {
with_mock_dir("mocks", {
test_that("test forecast", {
test_data <- read.csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short.csv')
test_data <- nixtlar::electricity
response <- timegpt_forecast(test_data, id_col="unique_id")
expect_s3_class(response, "data.frame") # output should be a data frame given that test_data is a data frame
expect_s3_class(response, "data.frame") # output should be a data frame given that nixtlar::electricity is a data frame
expect_true(all(c("unique_id", "ds", "TimeGPT") %in% names(response))) # should at least have columns ds and TimeGPT
expect_type(response$TimeGPT, "double") #TimeGPT should be numeric
})
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-timegpt_historic.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with_mock_dir("mocks", {
test_that("test historic", {
test_data <- nixtlar::electricity
response <- timegpt_historic(test_data, id_col="unique_id")
expect_s3_class(response, "data.frame") # output should be a data frame given that nixtlar::electricity is a data frame
expect_true(all(c("unique_id", "ds", "TimeGPT") %in% names(response))) # should have columns ds and TimeGPT
expect_type(response$TimeGPT, "double") #TimeGPT should be numeric
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Getting Started"
title: "Get Started"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{nixtlar}
Expand Down

0 comments on commit 2a38e20

Please sign in to comment.