Skip to content

Commit 674720d

Browse files
committed
Allow MASS to process dataFrames with 1 column
1 parent b729114 commit 674720d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

stumpy/core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,25 @@ def mass(Q, T, M_T=None, Σ_T=None):
652652
Note: Unlike the Matrix Profile I paper, here, M_T, Σ_T can be calculated
653653
once for all subsequences of T and passed in so the redundancy is removed
654654
"""
655+
Q = Q.copy()
655656
Q = np.asarray(Q)
656657
check_dtype(Q)
657658
m = Q.shape[0]
658659

660+
if Q.ndim == 2 and Q.shape[1] == 1: # pragma: no cover
661+
Q = Q.flatten()
662+
659663
if Q.ndim != 1: # pragma: no cover
660664
raise ValueError(f"Q is {Q.ndim}-dimensional and must be 1-dimensional. ")
661665

666+
T = T.copy()
662667
T = np.asarray(T)
663668
check_dtype(T)
664669
n = T.shape[0]
665670

671+
if T.ndim == 2 and T.shape[1] == 1: # pragma: no cover
672+
T = T.flatten()
673+
666674
if T.ndim != 1: # pragma: no cover
667675
raise ValueError(f"T is {T.ndim}-dimensional and must be 1-dimensional. ")
668676

@@ -736,17 +744,25 @@ def mass_absolute(Q, T):
736744
`See Mueen's Absolute Algorithm for Similarity Search \
737745
<https://www.cs.unm.edu/~mueen/MASS_absolute.m>`__
738746
"""
747+
Q = Q.copy()
739748
Q = np.asarray(Q)
740749
check_dtype(Q)
741750
m = Q.shape[0]
742751

752+
if Q.ndim == 2 and Q.shape[1] == 1: # pragma: no cover
753+
Q = Q.flatten()
754+
743755
if Q.ndim != 1: # pragma: no cover
744756
raise ValueError(f"Q is {Q.ndim}-dimensional and must be 1-dimensional. ")
745757

758+
T = T.copy()
746759
T = np.asarray(T)
747760
check_dtype(T)
748761
n = T.shape[0]
749762

763+
if T.ndim == 2 and T.shape[1] == 1: # pragma: no cover
764+
T = T.flatten()
765+
750766
if T.ndim != 1: # pragma: no cover
751767
raise ValueError(f"T is {T.ndim}-dimensional and must be 1-dimensional. ")
752768

0 commit comments

Comments
 (0)