Skip to content

Commit baf23a2

Browse files
committed
Refactor lag_matrix function to improve parameter handling and update deprecation warnings
1 parent 7656ae2 commit baf23a2

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

pyeeg/utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def poisson_onsets_fixed_N(N, dur=1.0, seed=None):
114114
rng = np.random.default_rng(seed)
115115
return np.sort(rng.uniform(0, dur, size=N))
116116

117-
# old and deprecated function, kept for personal use
117+
# deprecated function, kept for personal use
118118
def lag_matrix_(data, lag_samples=(-1, 0, 1), filling=np.nan, drop_missing=False):
119119
"""Helper function to create a matrix of lagged time series.
120120
@@ -149,7 +149,7 @@ def lag_matrix_(data, lag_samples=(-1, 0, 1), filling=np.nan, drop_missing=False
149149
Example
150150
-------
151151
>>> data = np.asarray([[1,2,3,4,5,6],[7,8,9,10,11,12]]).T
152-
>>> out = lag_matrix(data, (0,1))
152+
>>> out = lag_matrix_(data, (0,1))
153153
>>> out
154154
array([[ 1., 7., nan, nan],
155155
[ 2., 8., 1., 7.],
@@ -176,8 +176,8 @@ def lag_matrix_(data, lag_samples=(-1, 0, 1), filling=np.nan, drop_missing=False
176176

177177
return dframe.values
178178

179-
@deprecated_warning("filling", "drop_missing")
180-
def lag_matrix(x, lags, mode='full', fill_value=0., **kwargs):
179+
@deprecated_warning("filling", "drop_missing", "lag_samples")
180+
def lag_matrix(x, lags=(0,1), mode='full', fill_value=0., **kwargs):
181181
"""Helper function to create a Toeplitz matrix of lagged time series.
182182
183183
The lag can be arbitrarily spaced. Check other functions to create series of lags
@@ -217,12 +217,12 @@ def lag_matrix(x, lags, mode='full', fill_value=0., **kwargs):
217217
>>> data = np.asarray([[1,2,3,4,5,6],[7,8,9,10,11,12]]).T
218218
>>> out = lag_matrix(data, (-1, 0, 2), mode='full')
219219
>>> out # doctest: +NORMALIZE_WHITESPACE
220-
array( [[ 2, 1, 0, 8, 7, 0],
221-
[ 3, 2, 0, 9, 8, 0],
222-
[ 4, 3, 1, 10, 9, 7],
223-
[ 5, 4, 2, 11, 10, 8],
224-
[ 6, 5, 3, 12, 11, 9],
225-
[ 0, 6, 4, 0, 12, 10]])
220+
array([[ 2, 1, 0, 8, 7, 0],
221+
[ 3, 2, 0, 9, 8, 0],
222+
[ 4, 3, 1, 10, 9, 7],
223+
[ 5, 4, 2, 11, 10, 8],
224+
[ 6, 5, 3, 12, 11, 9],
225+
[ 0, 6, 4, 0, 12, 10]])
226226
"""
227227
if 'filling' in kwargs:
228228
fill_value = kwargs['filling']
@@ -231,6 +231,8 @@ def lag_matrix(x, lags, mode='full', fill_value=0., **kwargs):
231231
mode = 'valid'
232232
else:
233233
mode = 'full'
234+
if 'lag_samples' in kwargs:
235+
lags = kwargs['lag_samples']
234236

235237
x = np.atleast_2d(np.asarray(x))
236238
if x.shape[0] == 1:

0 commit comments

Comments
 (0)