setas¶
- class Stoner.core.setas.setas(row=False, bless=None)[source]¶
Bases:
MutableMapping
A Class that provides a mechanism for managing the column assignments in a DataFile like object.
Implements a MutableMapping bsed on the column_headers as the keys (with a few tweaks!).
Note
Iterating over setas will return the column assignments rather than the standard mapping behaviour of iterating over the keys. Otherwise the interface is essentially as a Mapping class.
Calling an existing setas instance and the constructor share the same signatgure:
setas(“xyzuvw”) setas([“x”],[“y”],[“z”],[“u”],[“v”],[“w”]) setas(x=”column_1”,y=3,column4=”z”)
- Keyword Arguments:
Attributes Summary
Create an exact copy of the current object.
Get the current column assignments.
Get the current column headers.
Determine if any columns are set.
Return the number of dimensions of the array.
Return a boolean array if not set.
Return a boolean array if column is set.
Guard the setas attribute.
Return the shape of the array that we think we are.
Quick access to the x column number.
Quick access to the y column numbers list.
Quick access to the z column numbers list.
Methods Summary
__call__
(*args, **kargs)Treat the current instance as a callable object and assign columns accordingly.
clear
()Clear the current setas attribute.
find_col
(col[, force_list])Indexes the column headers in order to locate a column of data.shape.
get
(key[, default])Implement a get method.
items
()Access mapping items.
keys
()Access mapping keys.
pop
(key[, default])Implement a get method.
popitem
()Return and clear a column assignment.
setdefault
(key[, default])Implement a setdefault method.
to_dict
()Return the setas attribute as a dictionary.
to_list
()Return the setas attribute as a list of letter types.
to_string
([encode])Return the setas attribute encoded as a string.
unset
([what])Remove column settings from the setas attribute in method call.
update
([other])Replace any assignments in self with assignments from other.
values
()Access mapping values.
Attributes Documentation
- clone¶
Create an exact copy of the current object.
- cols¶
Get the current column assignments.
- column_headers¶
Get the current column headers.
- empty¶
Determine if any columns are set.
- ndim¶
Return the number of dimensions of the array.
- not_set¶
Return a boolean array if not set.
- set¶
Return a boolean array if column is set.
- setas¶
Guard the setas attribute.
- shape¶
Return the shape of the array that we think we are.
- x¶
Quick access to the x column number.
Just a convenience read only property. If we want to change the setas.x value we should use the setas(x=1,y=2) style call (so that reset can be handled properly)
- y¶
Quick access to the y column numbers list.
- z¶
Quick access to the z column numbers list.
Methods Documentation
- __call__(*args, **kargs)[source]¶
Treat the current instance as a callable object and assign columns accordingly.
Variois forms of this method are accepted:
setas(“xyzuvw”) setas([“x”],[“y”],[“z”],[“u”],[“v”],[“w”]) setas(x=”column_1”,y=3,column4=”z”)
- Keyword Arguments:
_self (bool) – If True, make the call return a copy of the setas object, if False, return _object attribute, if None, return None. Default - False
reset (bool) – If False then preserve the existing set columns and simply add the new ones. Otherwise, clear all column assignments before setting new ones (default).
- clear()[source]¶
Clear the current setas attribute.
Notes
Equivalent to doing
setas.unset()
with no argument.
- find_col(col, force_list=False)[source]¶
Indexes the column headers in order to locate a column of data.shape.
Indexing can be by supplying an integer, a string, a regular expression, a slice or a list of any of the above.
Integer indices are simply checked to ensure that they are in range
String indices are first checked for an exact match against a column header if that fails they are then compiled to a regular expression and the first match to a column header is taken.
A regular expression index is simply matched against the column headers and the first match found is taken. This allows additional regular expression options such as case insensitivity.
A slice index is converted to a list of integers and processed as below
A list index returns the results of feading each item in the list at
find_col()
in turn.
- Parameters:
col (int, a string, a re, a slice or a list) – Which column(s) to retuirn indices for.
- Keyword Arguments:
force_list (bool) – Force the output always to be a list. Mainly for internal use only
- Returns:
The matching column index as an integer or a KeyError
- to_dict()[source]¶
Return the setas attribute as a dictionary.
If multiple columns are assigned to the same type, then the column names are returned as a list. If column headers are duplicated
- to_string(encode=False)[source]¶
Return the setas attribute encoded as a string.
Optionally replaces runs of 3 or more identical characters with a precediung digit.
- unset(what=None)[source]¶
Remove column settings from the setas attribute in method call.
- Parameters:
what (str,iterable,dict or None) – What to unset.
Notes
The what parameter determines what to unset, possible values are:
A single lets from xyzuvwdef - all column assignments of the corresponding type are unset
A column index type - all matching columns are unset
A list or other iterable of the above - all matching entries are unset
None - all setas assignments are cleared.