robjhyndman / tsfeatures

Time series features
http://pkg.robjhyndman.com/tsfeatures
253 stars 42 forks source link

error in stl_features #32

Closed jmablans closed 4 years ago

jmablans commented 4 years ago

Dear professor Hyndman,

Thank you very much for this very useful library.

I ran into some errors while applying this package to tiny time series. Shouldn't NA be returned when no value can be calculated?

Below a reprex with the generated errors or output in comments and my sessionInfo().

Thank you in advance and kind regards, Jan Blans

ts <- as.ts(c(1,1))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# Error in approx(idx, x[idx], tt, rule = 2) : 
#  need at least two non-NA values to interpolate
# In addition: Warning messages:
# 1: In min(x) : no non-missing arguments to min; returning Inf
# 2: In max(x) : no non-missing arguments to max; returning -Inf

ts <- as.ts(c(1,1,1))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# Error in approx(idx, x[idx], tt, rule = 2) : 
#  need at least two non-NA values to interpolate
# In addition: Warning messages:
# 1: In min(x) : no non-missing arguments to min; returning Inf
# 2: In max(x) : no non-missing arguments to max; returning -Inf

ts <- as.ts(c(1,1,0))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# no error:
# # A tibble: 1 x 8
#   nperiods seasonal_period trend  spike linearity curvature e_acf1 e_acf10
#      <dbl>           <dbl> <dbl>  <dbl>     <dbl>     <dbl>  <dbl>   <dbl>
# 1        0               1  0.75 0.0208     -1.22  2.22e-16 -0.667      NA

ts <- as.ts(c(1,0))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# Error in poly(seq(n), degree = 2L) : 
#   'degree' must be less than number of unique points

ts <- as.ts(c(0,1))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# Error in poly(seq(n), degree = 2L) : 
#   'degree' must be less than number of unique points

ts <- as.ts(c(0,0,0,0))
tsfeatures::tsfeatures(ts, features = c('stl_features'))
# Error in approx(idx, x[idx], tt, rule = 2) : 
#   need at least two non-NA values to interpolate
# In addition: Warning messages:
# 1: In min(x) : no non-missing arguments to min; returning Inf
# 2: In max(x) : no non-missing arguments to max; returning -Inf
Session info

``` R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] tsfeatures_1.0.1 fracdiff_1.4-2 loaded via a namespace (and not attached): [1] Rcpp_1.0.3 magrittr_1.5 forecast_8.9 munsell_0.5.0 colorspace_1.4-1 lattice_0.20-38 R6_2.4.1 rlang_0.4.1 [9] quadprog_1.5-7 fansi_0.4.0 TTR_0.23-5 xts_0.11-2 tools_3.6.1 quantmod_0.4-15 nnet_7.3-12 parallel_3.6.1 [17] grid_3.6.1 nlme_3.1-140 timeDate_3043.102 gtable_0.3.0 utf8_1.1.4 cli_1.1.0 urca_1.3-0 tseries_0.10-47 [25] assertthat_0.2.1 lazyeval_0.2.2 lmtest_0.9-37 tibble_2.1.3 lifecycle_0.1.0 crayon_1.3.4 purrr_0.3.3 ggplot2_3.2.1 [33] vctrs_0.2.0 zeallot_0.1.0 curl_4.2 compiler_3.6.1 pillar_1.4.2 backports_1.1.5 scales_1.1.0 pkgconfig_2.0.3 [41] zoo_1.8-6 ```

mitchelloharawild commented 4 years ago

The errors have been fixed in 5fc1a7912370195b92f5ccaf900bc33876cd29ec and 5fc1a7912370195b92f5ccaf900bc33876cd29ec