impedance.py
impedance.py copied to clipboard
[BUG] Circuit element not found when spaces are used in string
Describe the bug When spaces are placed inside parentheses of circuit string definitions, circuit elements cannot be found.
To Reproduce Steps to reproduce the behavior:
- Code which generates the error '...'
from impedance.models.circuits import CustomCircuit
circuit = circuit = 'R0-p(R1, C1)'
circuit = CustomCircuit(circuit, initial_guess=initial_guess)
- Full error info
*** ValueError: C not in allowed elements (dict_keys(['G', 'W', 's', 'Ws', 'La', 'K', 'Gs', 'L', 'TLMQ', 'C', 'R', 'T', 'CPE', 'p', 'Wo', '__builtins__']))
Expected behavior
Spaces should not affect the definition of a circuit, as they have no topological meaning, and are often inserted habitually when separating arguments of a function. This is common practice and will lead to many unnecessary errors. Suggest applying a simple .replace( ' ', '') to the string before it is parsed into a circuit to avoid this error.
Additional context Add any other context about the problem here.