Passed
Push — master ( cc7a4b...4d42d8 )
by Konstantinos
43s queued 14s
created

so_magic.data.datapoints.tabular_data_interface   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A TabularDataInterface.__len__() 0 4 1
A TabularDataInterface.iterrows() 0 4 1
A TabularDataInterface.nb_columns() 0 9 1
A TabularDataInterface.columns() 0 5 1
A TabularDataInterface.__iter__() 0 4 1
A TabularDataInterface.column() 0 11 1
A TabularDataInterface.rows() 0 5 1
A TabularDataInterface.nb_rows() 0 9 1
A TabularDataInterface.itercolumns() 0 4 1
A TabularDataInterface.row() 0 11 1
1
"""This module defines the TabularDataInterface interface."""
2
from typing import Union, Iterable
3
from abc import ABC, abstractmethod
4
5
6
__all__ = ['TabularDataInterface']
7
8
9
class TabularDataInterface(ABC):
10
    """Data points that have tabular structure and are loaded in memory.
11
12
    Classes implementing this interface represent Data points that can be represented
13
    as a table of rows an columns. One can imagine that each row (or column) represents a single observation
14
    (single data point) and each column (or row) one single attribute out of possibly many attributes.
15
16
    Classes implementing this interface have the ability to report on various
17
    elements and properties (eg rows, columns) of the underlying table-like data-structure.
18
    """
19
20
    @property
21
    @abstractmethod
22
    def columns(self) -> Iterable:
23
        """List of the column identifiers."""
24
        raise NotImplementedError
25
26
    @property
27
    @abstractmethod
28
    def rows(self) -> Iterable:
29
        """List of the row identifiers."""
30
        raise NotImplementedError
31
32
    @abstractmethod
33
    def column(self, identifier: Union[str, int]) -> Iterable:
34
        """Get the data inside a column of the table.
35
36
        Args:
37
            identifier (Union[str, int]): a primitive identifier to distinguish between the columns
38
39
        Returns:
40
            Iterable: the data contained in the table's requested column
41
        """
42
        raise NotImplementedError
43
44
    @abstractmethod
45
    def row(self, identifier: Union[str, int]) -> Iterable:
46
        """Get the data inside a row of the table.
47
48
        Args:
49
            identifier (Union[str, int]): a primitive identifier to distinguish between the rows
50
51
        Returns:
52
            Iterable: the data contained in the table's requested row
53
        """
54
        raise NotImplementedError
55
56
    @property
57
    @abstractmethod
58
    def nb_columns(self) -> int:
59
        """The number of the table's columns.
60
61
        Returns:
62
            int: the number of columns
63
        """
64
        raise NotImplementedError
65
66
    @property
67
    @abstractmethod
68
    def nb_rows(self) -> int:
69
        """The number of the table's rows.
70
71
        Returns:
72
            int: the number of rows
73
        """
74
        raise NotImplementedError
75
76
    @abstractmethod
77
    def iterrows(self) -> Iterable:
78
        """Iterate over the table's rows."""
79
        raise NotImplementedError
80
81
    @abstractmethod
82
    def itercolumns(self) -> Iterable:
83
        """Iterate over the table's columns."""
84
        raise NotImplementedError
85
86
    @abstractmethod
87
    def __len__(self) -> int:
88
        """The table's length as the number of rows."""
89
        raise NotImplementedError
90
91
    @abstractmethod
92
    def __iter__(self) -> Iterable:
93
        """Iterate over the table's rows."""
94
        raise NotImplementedError
95