From 8c72a78f56d1f87ca801495bec0c0d676d2ef6a5 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 30 Apr 2014 15:25:03 -0600 Subject: BUG: Fix __truediv__ bug in polytemplate.py file. The use of polytemplate is deprecated, this fix is only for a backport if needed. --- numpy/polynomial/polytemplate.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'numpy/polynomial/polytemplate.py') 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) -- cgit v1.2.1