text
stringlengths
0
828
except ValueError:
# this is an esoteric error, and this implementation
# forces a terrible solution. Sorry.
# using the standard escaping syntax in python is a mistake.
# if a value has a ""%"" inside (e.g. a password), a ValueError
# is raised, causing an issue
return cur_value
max_depth -= 1
return cur_value"
784,"def set(self, param, value):
"""""" sets the param to the value provided """"""
self.raw_dict[param] = value
self.manifest.set(self.feature_name, param, value)"
785,"def remove(self, param):
"""""" Remove a parameter from the manifest """"""
if self.has(param):
del(self.raw_dict[param])
self.manifest.remove_option(self.feature_name, param)"
786,"def set_if_empty(self, param, default):
"""""" Set the parameter to the default if it doesn't exist """"""
if not self.has(param):
self.set(param, default)"
787,"def to_dict(self):
"""""" Returns the context, fully specialized, as a dictionary """"""
return dict((k, str(self.get(k))) for k in self.raw_dict)"
788,"def write_to_manifest(self):
"""""" Overwrites the section of the manifest with the featureconfig's value """"""
self.manifest.remove_section(self.feature_name)
self.manifest.add_section(self.feature_name)
for k, v in self.raw_dict.items():
self.manifest.set(self.feature_name, k, v)"
789,"def mro_resolve(name, bases, dict):
""""""
Given a tuple of baseclasses and a dictionary that takes precedence
over any value in the bases, finds a value with the specified *name*
and returns it. Raises #KeyError if the value can not be found.
""""""
if name in dict:
return dict[name]
for base in bases:
if hasattr(base, name):
return getattr(base, name)
try:
return mro_resolve(name, base.__bases__, {})
except KeyError:
pass
raise KeyError(name)"
790,"def round_to_05(n, exp=None, mode='s'):
""""""
Round to the next 0.5-value.
This function applies the round function `func` to round `n` to the
next 0.5-value with respect to its exponent with base 10 (i.e.
1.3e-4 will be rounded to 1.5e-4) if `exp` is None or with respect
to the given exponent in `exp`.
Parameters
----------
n: numpy.ndarray
number to round
exp: int or numpy.ndarray
Exponent for rounding. If None, it will be computed from `n` to be the
exponents for base 10.
mode: {'s', 'l'}
rounding mode. If 's', it will be rounded to value whose absolute
value is below `n`, if 'l' it will rounded to the value whose absolute
value is above `n`.
Returns
-------
numpy.ndarray
rounded `n`
Examples
--------
The effects of the different parameters are show in the example below::
>>> from psyplot.plotter.simple import round_to_05
>>> a = [-100.3, 40.6, 8.7, -0.00023]
>>>round_to_05(a, mode='s')
array([ -1.00000000e+02, 4.00000000e+01, 8.50000000e+00,
-2.00000000e-04])
>>> round_to_05(a, mode='l')
array([ -1.50000000e+02, 4.50000000e+01, 9.00000000e+00,
-2.50000000e-04])""""""
n = np.asarray(n)
if exp is None:
exp = np.floor(np.log10(np.abs(n))) # exponent for base 10
ntmp = np.abs(n)/10.**exp # mantissa for base 10
if mode == 's':
n1 = ntmp
s = 1.
n2 = nret = np.floor(ntmp)
else:
n1 = nret = np.ceil(ntmp)
s = -1.
n2 = ntmp
return np.where(n1 - n2 > 0.5, np.sign(n)*(nret + s*0.5)*10.**exp,