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