impedance.py icon indicating copy to clipboard operation
impedance.py copied to clipboard

[BUG] Array-like types do not work when fitting a model

Open edmundsj opened this issue 3 years ago • 0 comments

Describe the bug When I pass array-like objects in as frequencies and impedances to the CustomCircuit.fit() method it throws an error if the frequencies and impedances are numpy arrays.

To Reproduce Steps to reproduce the behavior:

  1. Code which generates the error '...'
import pandas as pd
from impedance.models.circuits import CustomCircuit
data = pd.DataFrame({'freq': [0 ,1, 2], 'Z': [1, 2, 3]})

circuit = 'R0'
initial_guess = [10]
frequencies, Z = data.iloc[:,0], data.iloc[:,1]
circuit = CustomCircuit(circuit=circuit, initial_guess=initial_guess)
circuit.fit(frequencies, Z)

  1. Full error info
*** TypeError: frequencies is not of type np.ndarray

Expected behavior I expect any array-like objects (list, pandas series, etc.) to be automatically cast into a numpy array. This is standard behavior for numpy itself and most other packages I know of, and is as simple as adding a x = np.array(x) to the frequencies and impedances if for subsequent processing they absolutely must be numpy arrays.

Additional context Add any other context about the problem here.

edmundsj avatar Jun 02 '22 18:06 edmundsj