Fix: add special case to add typing
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Sometimes, typing/add.py tried to build MOpolynomial with only one coefficient.
This commit is contained in:
@@ -132,7 +132,7 @@ class MOstrPower(Molecule):
|
||||
|
||||
class MOMonomial(Molecule):
|
||||
|
||||
""" Monomial math object"""
|
||||
""" Monomial math object : ax^n"""
|
||||
|
||||
MAINOP = "*"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ __all__ = ["MOpolynomial"]
|
||||
|
||||
class MOpolynomial(Molecule):
|
||||
|
||||
""" MO polynomial"""
|
||||
""" MO polynomial: ax^n + ... + z (can't be a monomial)"""
|
||||
|
||||
MAINOP = "+"
|
||||
|
||||
@@ -39,6 +39,14 @@ class MOpolynomial(Molecule):
|
||||
<MOpolynomial 4x^3 + 1>
|
||||
>>> MOpolynomial('x', {0: 1, 3: 1})
|
||||
<MOpolynomial x^3 + 1>
|
||||
>>> MOpolynomial('x', [0, 0, 3])
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: A MOpolynomial can't be monomial it has to have more than one coefficient.
|
||||
>>> MOpolynomial('x', {3: 1})
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: A MOpolynomial can't be monomial it has to have more than one coefficient.
|
||||
|
||||
"""
|
||||
_variable = MO.factory(variable)
|
||||
@@ -58,6 +66,9 @@ class MOpolynomial(Molecule):
|
||||
raise TypeError("Coefs needs to be a dictionnary or a list")
|
||||
self._coefs = _coefs
|
||||
|
||||
if len(self._coefs) == 1:
|
||||
raise TypeError("A MOpolynomial can't be monomial it has to have more than one coefficient.")
|
||||
|
||||
monomials = OrderedDict()
|
||||
for deg in sorted(self._coefs.keys()):
|
||||
coef = self._coefs[deg]
|
||||
|
||||
Reference in New Issue
Block a user