Skip to content

Commit

Permalink
Remove scipy dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stijn committed Jan 17, 2024
1 parent dadfa2d commit 0634634
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
8 changes: 3 additions & 5 deletions frm/_frm_py/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"""
from typing import Union

from scipy.stats import zscore
from numpy import nan_to_num

import numpy as np
# https://stackoverflow.com/a/60617044
numeric = Union[int, float]

Expand Down Expand Up @@ -61,9 +59,9 @@ def standardise(timeseries: list[list]):
Database of standardised time series.
"""
try:
return nan_to_num(zscore(timeseries, axis=1))
return np.nan_to_num((timeseries - np.mean(timeseries, axis=1, keepdims=True)) / np.std(timeseries, axis=1, keepdims=True))
except ValueError:
return [nan_to_num(zscore(ts)) for ts in timeseries]
return [np.nan_to_num((ts - np.nanmean(ts)) / np.nanstd(ts)) for ts in timeseries]


# Defined in Lin, Keogh, Linardi, & Chiu (2003). A Symbolic Representation of Time Series,
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ classifiers = [
]
dependencies = [
"numpy",
"scipy",
]

[project.optional-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from scipy.stats import zscore

ts = [
[0, 1, 2, 2, 1, 0],
Expand Down Expand Up @@ -61,4 +60,4 @@
]

np.random.seed(0)
data = [zscore(np.random.random(np.random.randint(10, 1000))).tolist() for _ in range(100)]
data = [np.random.random(np.random.randint(10, 1000)).tolist() for _ in range(100)]

0 comments on commit 0634634

Please sign in to comment.