Skip to content

Commit

Permalink
STY: Fix up some remaining old-style exceptions.
Browse files Browse the repository at this point in the history
I think that is the end of it.
  • Loading branch information
charris committed Apr 5, 2011
1 parent b2793ea commit fd26303
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 42 deletions.
14 changes: 7 additions & 7 deletions numpy/core/_mx_datetime_parser.py
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
#-*- coding: latin-1 -*- #-*- coding: latin-1 -*-
""" """
Date/Time string parsing module. Date/Time string parsing module.
This code is a slightly modified version of Parser.py found in mx.DateTime This code is a slightly modified version of Parser.py found in mx.DateTime
Expand Down Expand Up @@ -540,8 +540,8 @@ def _parse_date(text):
try: try:
month = litmonthtable[litmonth] month = litmonthtable[litmonth]
except KeyError: except KeyError:
raise ValueError,\ raise ValueError(
'wrong month name: "%s"' % litmonth 'wrong month name: "%s"' % litmonth)
elif month: elif month:
month = int(month) month = int(month)
else: else:
Expand Down Expand Up @@ -726,8 +726,8 @@ def datetime_from_string(text):
return dt.datetime(year,month,day,hour,minute,second, microsecond) - \ return dt.datetime(year,month,day,hour,minute,second, microsecond) - \
dt.timedelta(minutes=offset) dt.timedelta(minutes=offset)
except ValueError, why: except ValueError, why:
raise RangeError,\ raise RangeError(
'Failed to parse "%s": %s' % (origtext, why) 'Failed to parse "%s": %s' % (origtext, why))


def date_from_string(text): def date_from_string(text):


Expand All @@ -745,8 +745,8 @@ def date_from_string(text):
try: try:
return dt.datetime(year,month,day) return dt.datetime(year,month,day)
except ValueError, why: except ValueError, why:
raise RangeError,\ raise RangeError(
'Failed to parse "%s": %s' % (text, why) 'Failed to parse "%s": %s' % (text, why))


def validateDateTimeString(text): def validateDateTimeString(text):


Expand Down
2 changes: 1 addition & 1 deletion numpy/core/getlimits.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _init(self, dtype):
fmt = '%12.5e' fmt = '%12.5e'
precname = 'half' precname = 'half'
else: else:
raise ValueError, repr(dtype) raise ValueError(repr(dtype))


machar = MachAr(lambda v:array([v], dtype), machar = MachAr(lambda v:array([v], dtype),
lambda v:_frz(v.astype(itype))[0], lambda v:_frz(v.astype(itype))[0],
Expand Down
16 changes: 8 additions & 8 deletions numpy/core/machar.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero): if any(temp1 - one != zero):
break break
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
b = one b = one
for _ in xrange(max_iterN): for _ in xrange(max_iterN):
b = b + b b = b + b
Expand All @@ -137,7 +137,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(itemp != 0): if any(itemp != 0):
break break
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
ibeta = itemp ibeta = itemp
beta = float_conv(ibeta) beta = float_conv(ibeta)


Expand All @@ -152,7 +152,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero): if any(temp1 - one != zero):
break break
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))


betah = beta / two betah = beta / two
a = one a = one
Expand All @@ -163,7 +163,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
if any(temp1 - one != zero): if any(temp1 - one != zero):
break break
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
temp = a + betah temp = a + betah
irnd = 0 irnd = 0
if any(temp-a != zero): if any(temp-a != zero):
Expand Down Expand Up @@ -191,7 +191,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
raise RuntimeError("could not determine machine tolerance " raise RuntimeError("could not determine machine tolerance "
"for 'negep', locals() -> %s" % (locals())) "for 'negep', locals() -> %s" % (locals()))
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
negep = -negep negep = -negep
epsneg = a epsneg = a


Expand All @@ -206,7 +206,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
a = a * beta a = a * beta
machep = machep + 1 machep = machep + 1
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
eps = a eps = a


# Determine ngrd # Determine ngrd
Expand Down Expand Up @@ -234,7 +234,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
i = i + 1 i = i + 1
k = k + k k = k + k
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
if ibeta != 10: if ibeta != 10:
iexp = i + 1 iexp = i + 1
mx = k + k mx = k + k
Expand Down Expand Up @@ -262,7 +262,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
else: else:
break break
else: else:
raise RuntimeError, msg % (_, one.dtype) raise RuntimeError(msg % (_, one.dtype))
minexp = -k minexp = -k


# Determine maxexp, xmax # Determine maxexp, xmax
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/numeric.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1109,9 +1109,9 @@ def rollaxis(a, axis, start=0):
start += n start += n
msg = 'rollaxis: %s (%d) must be >=0 and < %d' msg = 'rollaxis: %s (%d) must be >=0 and < %d'
if not (0 <= axis < n): if not (0 <= axis < n):
raise ValueError, msg % ('axis', axis, n) raise ValueError(msg % ('axis', axis, n))
if not (0 <= start < n+1): if not (0 <= start < n+1):
raise ValueError, msg % ('start', start, n+1) raise ValueError(msg % ('start', start, n+1))
if (axis < start): # it's been removed if (axis < start): # it's been removed
start -= 1 start -= 1
if axis==start: if axis==start:
Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/mingw32ccompiler.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _build_import_library_x86():
log.warn('Failed to build import library for gcc. Linking will fail.') log.warn('Failed to build import library for gcc. Linking will fail.')
#if not success: #if not success:
# msg = "Couldn't find import library, and failed to build it." # msg = "Couldn't find import library, and failed to build it."
# raise DistutilsPlatformError, msg # raise DistutilsPlatformError(msg)
return return


#===================================== #=====================================
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/_datasource.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def listdir(self):
""" """
if self._isurl(self._baseurl): if self._isurl(self._baseurl):
raise NotImplementedError, \ raise NotImplementedError(
"Directory listing of URLs, not supported yet." "Directory listing of URLs, not supported yet.")
else: else:
return os.listdir(self._baseurl) return os.listdir(self._baseurl)
6 changes: 3 additions & 3 deletions numpy/lib/npyio.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __getattribute__(self, key):
try: try:
return object.__getattribute__(self, '_obj')[key] return object.__getattribute__(self, '_obj')[key]
except KeyError: except KeyError:
raise AttributeError, key raise AttributeError(key)


def zipfile_factory(*args, **kwargs): def zipfile_factory(*args, **kwargs):
import zipfile import zipfile
Expand Down Expand Up @@ -353,8 +353,8 @@ def load(file, mmap_mode=None):
try: try:
return _cload(fid) return _cload(fid)
except: except:
raise IOError, \ raise IOError(
"Failed to interpret file %s as a pickle" % repr(file) "Failed to interpret file %s as a pickle" % repr(file))
finally: finally:
if own_fid: if own_fid:
fid.close() fid.close()
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/polynomial.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ def polyint(p, m=1, k=None):
if len(k) == 1 and m > 1: if len(k) == 1 and m > 1:
k = k[0]*NX.ones(m, float) k = k[0]*NX.ones(m, float)
if len(k) < m: if len(k) < m:
raise ValueError, \ raise ValueError(
"k must be a scalar or a rank-1 array of length 1 or >m." "k must be a scalar or a rank-1 array of length 1 or >m.")


truepoly = isinstance(p, poly1d) truepoly = isinstance(p, poly1d)
p = NX.asarray(p) p = NX.asarray(p)
Expand Down
12 changes: 6 additions & 6 deletions numpy/ma/core.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ def masked_where(condition, a, copy=True):


(cshape, ashape) = (cond.shape, a.shape) (cshape, ashape) = (cond.shape, a.shape)
if cshape and cshape != ashape: if cshape and cshape != ashape:
raise IndexError("Inconsistant shape between the condition and the input"\ raise IndexError("Inconsistant shape between the condition and the input"
" (got %s and %s)" % (cshape, ashape)) " (got %s and %s)" % (cshape, ashape))
if hasattr(a, '_mask'): if hasattr(a, '_mask'):
cond = mask_or(cond, a._mask) cond = mask_or(cond, a._mask)
Expand Down Expand Up @@ -2703,7 +2703,7 @@ def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
else: else:
msg = "Mask and data not compatible: data size is %i, " + \ msg = "Mask and data not compatible: data size is %i, " + \
"mask size is %i." "mask size is %i."
raise MaskError, msg % (nd, nm) raise MaskError(msg % (nd, nm))
copy = True copy = True
# Set the mask to the new value # Set the mask to the new value
if _data._mask is nomask: if _data._mask is nomask:
Expand Down Expand Up @@ -2930,7 +2930,7 @@ def __getitem__(self, indx):
# This test is useful, but we should keep things light... # This test is useful, but we should keep things light...
# if getmask(indx) is not nomask: # if getmask(indx) is not nomask:
# msg = "Masked arrays must be filled before they can be used as indices!" # msg = "Masked arrays must be filled before they can be used as indices!"
# raise IndexError, msg # raise IndexError(msg)
_data = ndarray.view(self, ndarray) _data = ndarray.view(self, ndarray)
dout = ndarray.__getitem__(_data, indx) dout = ndarray.__getitem__(_data, indx)
# We could directly use ndarray.__getitem__ on self... # We could directly use ndarray.__getitem__ on self...
Expand Down Expand Up @@ -2980,7 +2980,7 @@ def __setitem__(self, indx, value):
# This test is useful, but we should keep things light... # This test is useful, but we should keep things light...
# if getmask(indx) is not nomask: # if getmask(indx) is not nomask:
# msg = "Masked arrays must be filled before they can be used as indices!" # msg = "Masked arrays must be filled before they can be used as indices!"
# raise IndexError, msg # raise IndexError(msg)
_data = ndarray.view(self, ndarray.__getattribute__(self, '_baseclass')) _data = ndarray.view(self, ndarray.__getattribute__(self, '_baseclass'))
_mask = ndarray.__getattribute__(self, '_mask') _mask = ndarray.__getattribute__(self, '_mask')
if isinstance(indx, basestring): if isinstance(indx, basestring):
Expand Down Expand Up @@ -3779,7 +3779,7 @@ def __ipow__(self, other):
def __float__(self): def __float__(self):
"Convert to float." "Convert to float."
if self.size > 1: if self.size > 1:
raise TypeError("Only length-1 arrays can be converted "\ raise TypeError("Only length-1 arrays can be converted "
"to Python scalars") "to Python scalars")
elif self._mask: elif self._mask:
warnings.warn("Warning: converting a masked element to nan.") warnings.warn("Warning: converting a masked element to nan.")
Expand All @@ -3789,7 +3789,7 @@ def __float__(self):
def __int__(self): def __int__(self):
"Convert to int." "Convert to int."
if self.size > 1: if self.size > 1:
raise TypeError("Only length-1 arrays can be converted "\ raise TypeError("Only length-1 arrays can be converted "
"to Python scalars") "to Python scalars")
elif self._mask: elif self._mask:
raise MaskError('Cannot convert masked element to a Python int.') raise MaskError('Cannot convert masked element to a Python int.')
Expand Down
4 changes: 2 additions & 2 deletions numpy/oldnumeric/ma.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ def __array__ (self, t=None, context=None):
"numeric because data\n is masked in one or "\ "numeric because data\n is masked in one or "\
"more locations."); "more locations.");
return self._data return self._data
#raise MAError, \ #raise MAError(
# """Cannot automatically convert masked array to numeric because data # """Cannot automatically convert masked array to numeric because data
# is masked in one or more locations. # is masked in one or more locations.
# """ # """)
else: else:
func, args, i = context func, args, i = context
fills = ufunc_fills.get(func) fills = ufunc_fills.get(func)
Expand Down
3 changes: 2 additions & 1 deletion numpy/oldnumeric/precision.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def _lookup(table, key, required_bits):
for bits, typecode in lst: for bits, typecode in lst:
if bits >= required_bits: if bits >= required_bits:
return typecode return typecode
raise PrecisionError, key+" of "+str(required_bits)+" bits not available on this system" raise PrecisionError(key + " of " + str(required_bits) +
" bits not available on this system")


Character = 'c' Character = 'c'


Expand Down
8 changes: 4 additions & 4 deletions numpy/oldnumeric/random_array.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def seed(x=0, y=0):
mt.seed((x,y)) mt.seed((x,y))


def get_seed(): def get_seed():
raise NotImplementedError, \ raise NotImplementedError(
"If you want to save the state of the random number generator.\n"\ "If you want to save the state of the random number generator.\n"
"Then you should use obj = numpy.random.get_state() followed by.\n"\ "Then you should use obj = numpy.random.get_state() followed by.\n"
"numpy.random.set_state(obj)." "numpy.random.set_state(obj).")


def random(shape=[]): def random(shape=[]):
"random(n) or random([n, m, ...]) returns array of random numbers" "random(n) or random([n, m, ...]) returns array of random numbers"
Expand Down
6 changes: 3 additions & 3 deletions numpy/testing/nulltester.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class NullTester(object): class NullTester(object):
def test(self, labels=None, *args, **kwargs): def test(self, labels=None, *args, **kwargs):
raise ImportError, \ raise ImportError(
'Need nose >=0.10 for tests - see %s' % \ 'Need nose >=0.10 for tests - see %s' %
'http://somethingaboutorange.com/mrl/projects/nose' 'http://somethingaboutorange.com/mrl/projects/nose')
bench = test bench = test

0 comments on commit fd26303

Please sign in to comment.