diff options
Diffstat (limited to 'numpy/polynomial/polytemplate.py')
-rw-r--r-- | numpy/polynomial/polytemplate.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/numpy/polynomial/polytemplate.py b/numpy/polynomial/polytemplate.py index eeacf24fb..6c60ab3b2 100644 --- a/numpy/polynomial/polytemplate.py +++ b/numpy/polynomial/polytemplate.py @@ -14,6 +14,7 @@ from __future__ import division, absolute_import, print_function import string import sys import warnings +from number import Number from numpy import ModuleDeprecationWarning @@ -287,15 +288,13 @@ class $name(pu.PolyBase) : return self.__floordiv__(other) def __truediv__(self, other) : - # there is no true divide if the rhs is not a scalar, although it + # there is no true divide if the rhs is not a Number, although it # could return the first n elements of an infinite series. # It is hard to see where n would come from, though. - if np.isscalar(other) : - # this might be overly restrictive - coef = self.coef/other - return self.__class__(coef, self.domain, self.window) - else : - return NotImplemented + if not isinstance(other, Number) or isinstance(other, bool): + form = "unsupported types for true division: '%s', '%s'" + raise TypeError(form % (type(self), type(other))) + return self.__floordiv__(other) def __floordiv__(self, other) : """Returns the quotient.""" @@ -384,20 +383,14 @@ class $name(pu.PolyBase) : return self.__rfloordiv__(other) def __rtruediv__(self, other) : - # there is no true divide if the rhs is not a scalar, although it - # could return the first n elements of an infinite series. - # It is hard to see where n would come from, though. - if len(self.coef) == 1 : - try : - quo, rem = ${nick}div(other, self.coef[0]) - except : - return NotImplemented - return self.__class__(quo, self.domain, self.window) + # An instance of PolyBase is not considered a + # Number. + return NotImplemented def __rfloordiv__(self, other) : try : quo, rem = ${nick}div(other, self.coef) - except : + except: return NotImplemented return self.__class__(quo, self.domain, self.window) |