class StringConverter:
Factory class for function transforming a string into another object (int, float).
After initialization, an instance can be called to transform a string into another object. If the string is recognized as representing a missing value, a default value is returned.
locked
parameter.dtype
, specifies the input data type, used to define a basic
function and a default value for missing data. For example, when
dtype
is float, the func
attribute is set to float
and the
default value to np.nan
. If a function, this function is used to
convert a string to another object. In this case, it is recommended
to give an associated default value as input.StringConverter
tries to supply a reasonable default value.Class Method | upgrade_mapper |
Upgrade the mapper of a StringConverter by adding a new function and its corresponding default. |
Class Method | _dtypeortype |
Returns dtype for datetime64 and type of dtype otherwise. |
Class Method | _find_map_entry |
Undocumented |
Class Method | _getdtype |
Returns the dtype of the input variable. |
Class Method | _getsubdtype |
Returns the type of the dtype of the input variable. |
Method | __call__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | _do_upgrade |
Undocumented |
Method | _loose_call |
Undocumented |
Method | _strict_call |
Undocumented |
Method | iterupgrade |
Undocumented |
Method | update |
Set StringConverter attributes directly. |
Method | upgrade |
Find the best converter for a given string, and return the result. |
Class Variable | _mapper |
Undocumented |
Instance Variable | _callingfunction |
Undocumented |
Instance Variable | _checked |
Undocumented |
Instance Variable | _initial_default |
Undocumented |
Instance Variable | _locked |
Undocumented |
Instance Variable | _status |
Undocumented |
Instance Variable | default |
Undocumented |
Instance Variable | func |
Undocumented |
Instance Variable | missing_values |
Undocumented |
Instance Variable | type |
Undocumented |
Upgrade the mapper of a StringConverter by adding a new function and its corresponding default.
The input function (or sequence of functions) and its associated default value (if any) is inserted in penultimate position of the mapper. The corresponding type is estimated from the dtype of the default value.
>>> import dateutil.parser >>> import datetime >>> dateparser = dateutil.parser.parse >>> defaultdate = datetime.date(2000, 1, 1) >>> StringConverter.upgrade_mapper(dateparser, default=defaultdate)
Undocumented
Set StringConverter attributes directly.
StringConverter
tries to supply a reasonable default value.missing_values
are cleared. The default is ''
.update
takes the same parameters as the constructor of
StringConverter
, except that func
does not accept a dtype
whereas dtype_or_func
in the constructor does.
Find the best converter for a given string, and return the result.
The supplied string value
is converted by testing different
converters in order. First the func
method of the
StringConverter
instance is tried, if this fails other available
converters are tried. The order in which these other converters
are tried is determined by the _status
attribute of the instance.
value
with the appropriate converter.