Skip to content

Commit e830538

Browse files
authored
Merge pull request #157 from florisvb/array-like-inputs
handling array-like inputs
2 parents 5d96072 + 2437967 commit e830538

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

pynumdiff/basis_fit/_basis_fit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def spectraldiff(x, dt, params=None, options=None, high_freq_cutoff=None, even_e
3838
# make derivative go to zero at ends (optional)
3939
if pad_to_zero_dxdt:
4040
padding = 100
41-
pre = x[0]*np.ones(padding) # extend the edges
42-
post = x[-1]*np.ones(padding)
43-
x = np.hstack((pre, x, post))
41+
pre = getattr(x, 'values', x)[0]*np.ones(padding) # getattr to use .values if x is a pandas Series
42+
post = getattr(x, 'values', x)[-1]*np.ones(padding)
43+
x = np.hstack((pre, x, post)) # extend the edges
4444
kernel = utility.mean_kernel(padding//2)
4545
x_hat = utility.convolutional_smoother(x, kernel) # smooth the edges in
4646
x_hat[padding:-padding] = x[padding:-padding] # replace middle with original signal

pynumdiff/finite_difference/_finite_difference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def finitediff(x, dt, num_iterations, order):
1717
if num_iterations < 1: raise ValueError("num_iterations must be >0")
1818
if order not in [1, 2, 4]: raise ValueError("order must be 1, 2, or 4")
1919

20-
x_hat = x # preserve a reference to x, because if iterating we need it to find the final constant of integration
20+
x_hat = np.asarray(x) # allows for array-like. Preserve reference to x, for finding the final constant of integration
2121
dxdt_hat = np.zeros(x.shape) # preallocate reusable memory
2222

2323
# For all but the last iteration, do the differentate->integrate smoothing loop, being careful with endpoints

0 commit comments

Comments
 (0)