Skip to content

Commit b5cf0c5

Browse files
committed
Fixed #83 Check for NaN
1 parent 18d5b97 commit b5cf0c5

File tree

8 files changed

+29
-0
lines changed

8 files changed

+29
-0
lines changed

stumpy/core.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ def z_norm(a, axis=0):
7373
return (a - np.mean(a, axis, keepdims=True)) / np.std(a, axis, keepdims=True)
7474

7575

76+
def check_nan(a): # pragma: no cover
77+
"""
78+
Check if the array contains NaNs
79+
80+
Raises
81+
------
82+
ValueError
83+
If the array contains a NaN
84+
"""
85+
86+
if np.any(np.isnan(a)):
87+
msg = f"Input array contains one or more NaNs"
88+
raise ValueError(msg)
89+
90+
return
91+
92+
7693
def check_dtype(a, dtype=np.floating): # pragma: no cover
7794
"""
7895
Check if the array type of `a` is of type specified by `dtype` parameter.

stumpy/gpu_stump.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,14 @@ def gpu_stump(
404404

405405
T_A = np.asarray(T_A)
406406
core.check_dtype(T_A)
407+
core.check_nan(T_A)
407408
if T_B is None: # Self join!
408409
T_B = T_A
409410
ignore_trivial = True
410411
T_B = np.asarray(T_B)
411412

412413
core.check_dtype(T_B)
414+
core.check_nan(T_B)
413415
core.check_window_size(m)
414416

415417
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover

stumpy/mstump.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ def mstump(T, m):
437437
raise ValueError(f"{err}")
438438

439439
core.check_dtype(T)
440+
core.check_nan(T)
440441
core.check_window_size(m)
441442

442443
d = T.shape[0]

stumpy/mstumped.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def mstumped(dask_client, T, m):
6464
raise ValueError(f"{err}")
6565

6666
core.check_dtype(T)
67+
core.check_nan(T)
6768
core.check_window_size(m)
6869

6970
d = T.shape[0]

stumpy/stamp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def stamp(T_A, T_B, m, ignore_trivial=False):
126126
"""
127127

128128
core.check_dtype(T_A)
129+
core.check_nan(T_A)
129130
core.check_dtype(T_B)
131+
core.check_nan(T_B)
130132
core.check_window_size(m)
131133
subseq_T_B = core.rolling_window(T_B, m)
132134
excl_zone = int(np.ceil(m / 2))

stumpy/stomp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ def stomp(T_A, m, T_B=None, ignore_trivial=True):
6464
Note that left and right matrix profiles are only available for self-joins.
6565
"""
6666
core.check_dtype(T_A)
67+
core.check_nan(T_A)
6768
if T_B is None:
6869
T_B = T_A
6970
core.check_dtype(T_B)
71+
core.check_nan(T_B)
7072
core.check_window_size(m)
7173

7274
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover

stumpy/stump.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def stump(T_A, m, T_B=None, ignore_trivial=True):
391391

392392
T_A = np.asarray(T_A)
393393
core.check_dtype(T_A)
394+
core.check_nan(T_A)
394395
if T_B is None: # Self join!
395396
T_B = T_A
396397
ignore_trivial = True
@@ -402,6 +403,7 @@ def stump(T_A, m, T_B=None, ignore_trivial=True):
402403
raise ValueError(f"T_B is {T_B.ndim}-dimensional and must be 1-dimensional")
403404

404405
core.check_dtype(T_B)
406+
core.check_nan(T_B)
405407
core.check_window_size(m)
406408

407409
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover

stumpy/stumped.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def stumped(dask_client, T_A, m, T_B=None, ignore_trivial=True):
8383

8484
T_A = np.asarray(T_A)
8585
core.check_dtype(T_A)
86+
core.check_nan(T_A)
8687
if T_B is None:
8788
T_B = T_A
8889
T_B = np.asarray(T_B)
@@ -93,6 +94,7 @@ def stumped(dask_client, T_A, m, T_B=None, ignore_trivial=True):
9394
raise ValueError(f"T_B is {T_B.ndim}-dimensional and must be 1-dimensional")
9495

9596
core.check_dtype(T_B)
97+
core.check_nan(T_B)
9698
core.check_window_size(m)
9799

98100
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover

0 commit comments

Comments
 (0)