setas

class Stoner.core.setas.setas(row=False, bless=None)[source]

Bases: collections.abc.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
  • _self (bool) – If True, make the call return a copy of the setas object, if False, return _object attribute, if None, return None

  • 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).

Attributes Summary

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.

y

Quick access to the y column numbers list.

z

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 attrbute.

find_col(col[, force_list])

Indexes the column headers in order to locate a column of data.shape.

get(name[, default])

Implement a get method.

items()

Access mapping items.

keys()

Acess mapping keys.

pop(name[, default])

Implement a get method.

popitem()

Return and clear a column assignment.

setdefault(name[, 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 attrbute.

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 experssion, 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

get(name, default=None)[source]

Implement a get method.

items()[source]

Access mapping items.

Mapping items iterates over keys and values.

keys()[source]

Acess mapping keys.

Mapping keys are the same as iterating over the unique headers

pop(name, default=None)[source]

Implement a get method.

popitem()[source]

Return and clear a column assignment.

setdefault(name, default=None)[source]

Implement a setdefault method.

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_list()[source]

Return the setas attribute as a list of letter types.

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.

update(other=(), **kwds)[source]

Replace any assignments in self with assignments from other.

values()[source]

Access mapping values.

Mapping values are the same as iterating over setas.