module documentation
A collection of functions designed to help I/O with ascii files.
Class |
|
Object to split a string at a given delimiter or at given places. |
Class |
|
Object to validate a list of strings to use as field names. |
Class |
|
Factory class for function transforming a string into another object (int, float). |
Exception |
|
Warning issued when a string converter has a problem. |
Exception |
|
Exception raised when an error occurs in a converter for string values. |
Exception |
|
Exception raised when an attempt is made to upgrade a locked converter. |
Function | easy |
Convenience function to create a np.dtype object. |
Function | flatten |
Unpack a structured data-type by collapsing nested fields and/or fields with a shape. |
Function | has |
Returns whether one or several fields of a dtype are nested. |
Function | str2bool |
Tries to transform a string supposed to represent a boolean to a boolean. |
Function | _decode |
Decode bytes from binary input streams. |
Function | _is |
Check whether obj behaves like a bytes object. |
Function | _is |
Check whether obj behaves like a string. |
Convenience function to create a np.dtype
object.
The function processes the input dtype
and matches it with the given
names.
Parameters
- ndtype : var
- Definition of the dtype. Can be any string or dictionary recognized
by the
np.dtype
function, or a sequence of types. - names : str or sequence, optional
- Sequence of strings to use as field names for a structured dtype.
For convenience,
names
can be a string of a comma-separated list of names. - defaultfmt : str, optional
- Format string used to define missing names, such as "f%i" (default) or "fields_%02i".
- validationargs : optional
- A series of optional arguments used to initialize a
NameValidator
.
Examples
>>> np.lib._iotools.easy_dtype(float) dtype('float64') >>> np.lib._iotools.easy_dtype("i4, f8") dtype([('f0', '<i4'), ('f1', '<f8')]) >>> np.lib._iotools.easy_dtype("i4, f8", defaultfmt="field_%03i") dtype([('field_000', '<i4'), ('field_001', '<f8')])
>>> np.lib._iotools.easy_dtype((int, float, float), names="a,b,c") dtype([('a', '<i8'), ('b', '<f8'), ('c', '<f8')]) >>> np.lib._iotools.easy_dtype(float, names="a,b,c") dtype([('a', '<f8'), ('b', '<f8'), ('c', '<f8')])
Unpack a structured data-type by collapsing nested fields and/or fields with a shape.
Note that the field names are lost.
Parameters
- ndtype : dtype
- The datatype to collapse
- flatten_base : bool, optional
- If True, transform a field with a shape into several fields. Default is False.
Examples
>>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float), ... ('block', int, (2, 3))]) >>> np.lib._iotools.flatten_dtype(dt) [dtype('S4'), dtype('float64'), dtype('float64'), dtype('int64')] >>> np.lib._iotools.flatten_dtype(dt, flatten_base=True) [dtype('S4'), dtype('float64'), dtype('float64'), dtype('int64'), dtype('int64'), dtype('int64'), dtype('int64'), dtype('int64'), dtype('int64')]
Returns whether one or several fields of a dtype are nested.
Parameters
- ndtype : dtype
- Data-type of a structured array.
Raises
- AttributeError
- If
ndtype
does not have anames
attribute.
Examples
>>> dt = np.dtype([('name', 'S4'), ('x', float), ('y', float)]) >>> np.lib._iotools.has_nested_fields(dt) False
Tries to transform a string supposed to represent a boolean to a boolean.
Parameters
- value : str
- The string that is transformed to a boolean.
Returns
- boolval : bool
- The boolean representation of
value
.
Raises
- ValueError
- If the string is not 'True' or 'False' (case independent)
Examples
>>> np.lib._iotools.str2bool('TRUE') True >>> np.lib._iotools.str2bool('false') False