summaryrefslogtreecommitdiff
path: root/numpy/polynomial/_polybase.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial/_polybase.py')
-rw-r--r--numpy/polynomial/_polybase.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py
index 253aa74e8..7616b95c7 100644
--- a/numpy/polynomial/_polybase.py
+++ b/numpy/polynomial/_polybase.py
@@ -347,10 +347,16 @@ class ABCPolyBase(abc.ABC):
out += " "
power = str(i + 1)
# Polynomial coefficient
- if coef >= 0:
+ try:
+ if coef >= 0:
+ next_term = f"+ {coef}"
+ else:
+ next_term = f"- {-coef}"
+ # The coefficient array can be an object array with elements that
+ # will raise a TypeError with >= 0 (e.g. strings or Python
+ # complex). In this case, represent the coeficient as-is.
+ except TypeError:
next_term = f"+ {coef}"
- else:
- next_term = f"- {-coef}"
# Polynomial term
next_term += term_method(power, "x")
# Length of the current line with next term added