Skip to content

Commit 649777e

Browse files
authored
Merge pull request #11 from felixcremer/iaaft_nan
If there is a NaN value in the time series, the `aaft` and `iaaft` methods return the sorted time series. This PR: * Adds check for NaNs in `aaft` and `iaaft` * Throw DomainError with NaN input to `aaft` and `iaaft` * Add tests for NaN input for `aaft` and `iaaft`
2 parents 5a70855 + acf9bf8 commit 649777e

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/aaft.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ J. Theiler et al., Physica D *58* (1992) 77-94 (1992).
1414
1515
"""
1616
function aaft(ts::AbstractArray{T, 1} where T)
17+
any(isnan.(ts)) && throw(DomainError(NaN, "The input must not contain NaN values"))
1718
n = length(ts)
1819

1920
# Indices that would sort `ts` in ascending order

src/iaaft.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ PMID 10062864. [https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.77.635
2727
"""
2828
function iaaft(ts::AbstractVector{T} where T;
2929
n_maxiter = 200, tol = 1e-6, n_windows = 50)
30-
30+
any(isnan.(ts)) && throw(DomainError(NaN,"The input must not contain NaN values."))
31+
3132
# Sorted version of the original time series
3233
original_sorted = sort(ts)
3334

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ using TimeseriesSurrogates
33
ENV["GKSwstype"] = "100"
44

55
ts = cumsum(randn(1000))
6+
ts_nan =cumsum(randn(100))
7+
ts_nan[1] = NaN
68

79
@testset "Constrained surrogates" begin
810
@testset "Random shuffle" begin
@@ -29,6 +31,7 @@ ts = cumsum(randn(1000))
2931
@test length(ts) == length(surrogate)
3032
#@test all(ts .!= surrogate)
3133
@test all(sort(ts) .== sort(surrogate))
34+
@test_throws DomainError aaft(ts_nan)
3235
end
3336

3437
@testset "IAAFT" begin
@@ -44,6 +47,7 @@ ts = cumsum(randn(1000))
4447
@test length(ts) == length(surrogates[1])
4548
#@test all(ts .!= surrogates[end])
4649
@test all(sort(ts) .== sort(surrogates[end]))
50+
@test_throws DomainError iaaft(ts_nan)
4751
end
4852

4953
@testset "WIAAFT" begin

0 commit comments

Comments
 (0)