so_magic.data.datapoints package

Submodules

so_magic.data.datapoints.datapoints module

class so_magic.data.datapoints.datapoints.AbstractTabularData(observations, attributes)[source]

Bases: so_magic.data.datapoints.datapoints.StructuredData, so_magic.data.datapoints.tabular_data_interface.TabularDataInterface, abc.ABC

Tabular Data with known attributes of interest.

Classes inheriting from this abstract class, gain both capabilities of structured data in terms of their attributes and capabilities of a data table in terms of column, rows, etc.

exception so_magic.data.datapoints.datapoints.DatapointsCreationError(msg)[source]

Bases: Exception

class so_magic.data.datapoints.datapoints.DatapointsFactory[source]

Bases: object

Factory to construct Datapoints objects.

A class that registers objects (constructors), which can be “called” to return (create) an object that implements the DatapointsInterface interface.

Also, exposes the ‘create’ factory method that given runtime arguments, returns an object that implements the DatapointsInterface interface by delegating the creation process to one of the registered constructors.

constructors = {'structured-data': <class 'so_magic.data.datapoints.datapoints.StructuredData'>, 'tabular-data': <class 'so_magic.data.datapoints.datapoints.TabularData'>}
classmethod create(name, *args, **kwargs)Iterable[source]

Create a Datapoints instance by using a registered “constructor”.

Parameters

name (str) – the registered name of the “constructor” to use

Raises
  • KeyError – happens if the input name is not found in the registry

  • DatapointsCreationError – in case the object instantiation operation fails

Returns

instance implementing the DatapointsInterface

Return type

Iterable

classmethod register_constructor(name: str)[source]

Register, using a unique name, an object as a “runnable” constructor.

A decorator method that should decorate a callable” The callable should return (create) an object that implements the DatapointsInterface interface.

Parameters

name (str) – the name under which to register the “constructor”

class so_magic.data.datapoints.datapoints.DatapointsInterface[source]

Bases: abc.ABC

Represent multiple data points out of a collection of data.

Classes implementing this interface, provide to their object instances (eg objects created using the classes constructor method) the ‘observations’ property.

The ‘observations’ property should hold the information about the datapoints.

abstract property observations: Iterable

The collection of datapoints is referenced through this property.

class so_magic.data.datapoints.datapoints.StructuredData(observations, attributes)[source]

Bases: so_magic.data.datapoints.datapoints.DatapointsInterface, so_magic.data.datapoints.datapoints.StructuredDataInterface

Structured data. There are specific attributes/variables per observation.

Instances of this class represent collections of data (multiple data points aka observations). Each data point is expected to hold information about the specified attributes and that is why we are dealing with structured data/information in contrast to ie image data or sound data.

Parameters
  • observations (object) – a reference to the actual datapoints object

  • attributes (object) – a reference to the attributes object

property attributes

The set of attributes is referenced through this property.

property observations

The collection of datapoints is referenced through this property.

class so_magic.data.datapoints.datapoints.StructuredDataInterface[source]

Bases: abc.ABC

Data points that are expected to have a specific set of attributes.

Classes implementing this interface, provide to their object instances (eg objects created using the classes constructor method) the ‘attributes’ property.

The ‘attributes’ property should hold the information about the attributes, that each data point (observation) is expected to have.

abstract property attributes: Iterable

The set of attributes is referenced through this property.

class so_magic.data.datapoints.datapoints.TabularData(observations, attributes, retriever, iterator, mutator)[source]

Bases: so_magic.data.datapoints.datapoints.AbstractTabularData

Table-like datapoints that are loaded in memory

add_column(values, column_name, **kwargs)[source]
property attributes

The set of attributes is referenced through this property.

column(identifier)[source]

Get the data inside a column of the table.

Parameters

identifier (Union[str, int]) – a primitive identifier to distinguish between the columns

Returns

the data contained in the table’s requested column

Return type

Iterable

property columns: Iterable

List of the column identifiers.

get_categorical_attributes()[source]
get_numerical_attributes()[source]
itercolumns()[source]

Iterate over the table’s columns.

iterrows()[source]

Iterate over the table’s rows.

property nb_columns

The number of the table’s columns.

Returns

the number of columns

Return type

int

property nb_rows

The number of the table’s rows.

Returns

the number of rows

Return type

int

row(identifier)[source]

Get the data inside a row of the table.

Parameters

identifier (Union[str, int]) – a primitive identifier to distinguish between the rows

Returns

the data contained in the table’s requested row

Return type

Iterable

property rows: Iterable

List of the row identifiers.

so_magic.data.datapoints.tabular_data_interface module

This module defines the TabularDataInterface interface.

class so_magic.data.datapoints.tabular_data_interface.TabularDataInterface[source]

Bases: abc.ABC

Data points that have tabular structure and are loaded in memory.

Classes implementing this interface represent Data points that can be represented as a table of rows an columns. One can imagine that each row (or column) represents a single observation (single data point) and each column (or row) one single attribute out of possibly many attributes.

Classes implementing this interface have the ability to report on various elements and properties (eg rows, columns) of the underlying table-like data-structure.

abstract column(identifier: Union[str, int])Iterable[source]

Get the data inside a column of the table.

Parameters

identifier (Union[str, int]) – a primitive identifier to distinguish between the columns

Returns

the data contained in the table’s requested column

Return type

Iterable

abstract property columns: Iterable

List of the column identifiers.

abstract itercolumns()Iterable[source]

Iterate over the table’s columns.

abstract iterrows()Iterable[source]

Iterate over the table’s rows.

abstract property nb_columns: int

The number of the table’s columns.

Returns

the number of columns

Return type

int

abstract property nb_rows: int

The number of the table’s rows.

Returns

the number of rows

Return type

int

abstract row(identifier: Union[str, int])Iterable[source]

Get the data inside a row of the table.

Parameters

identifier (Union[str, int]) – a primitive identifier to distinguish between the rows

Returns

the data contained in the table’s requested row

Return type

Iterable

abstract property rows: Iterable

List of the row identifiers.

Module contents

class so_magic.data.datapoints.DatapointsFactory[source]

Bases: object

Factory to construct Datapoints objects.

A class that registers objects (constructors), which can be “called” to return (create) an object that implements the DatapointsInterface interface.

Also, exposes the ‘create’ factory method that given runtime arguments, returns an object that implements the DatapointsInterface interface by delegating the creation process to one of the registered constructors.

constructors = {'structured-data': <class 'so_magic.data.datapoints.datapoints.StructuredData'>, 'tabular-data': <class 'so_magic.data.datapoints.datapoints.TabularData'>}
classmethod create(name, *args, **kwargs)Iterable[source]

Create a Datapoints instance by using a registered “constructor”.

Parameters

name (str) – the registered name of the “constructor” to use

Raises
  • KeyError – happens if the input name is not found in the registry

  • DatapointsCreationError – in case the object instantiation operation fails

Returns

instance implementing the DatapointsInterface

Return type

Iterable

classmethod register_constructor(name: str)[source]

Register, using a unique name, an object as a “runnable” constructor.

A decorator method that should decorate a callable” The callable should return (create) an object that implements the DatapointsInterface interface.

Parameters

name (str) – the name under which to register the “constructor”