1
|
|
|
from so_magic.data.backend.engine_specs import EngineTabularRetriever, EngineTabularIterator, EngineTabularMutator |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
__all__ = ['PDTabularRetrieverDelegate', 'PDTabularIteratorDelegate', 'PDTabularMutatorDelegate'] |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
# DELEGATES |
8
|
|
|
# User defined (engine dependent implementations of tabular operations) |
9
|
|
|
|
10
|
|
|
class PDTabularRetrieverDelegate(EngineTabularRetriever): |
11
|
|
|
"""The observation object is the same as the one your return from 'from_json_lines'""" |
12
|
|
|
|
13
|
|
|
@classmethod |
14
|
|
|
def column(cls, identifier, data): |
15
|
|
|
return data.observations[identifier] |
16
|
|
|
|
17
|
|
|
@classmethod |
18
|
|
|
def row(cls, identifier, data): |
19
|
|
|
return data.observations.loc(identifier) |
20
|
|
|
|
21
|
|
|
@classmethod |
22
|
|
|
def nb_columns(cls, data): |
23
|
|
|
return len(data.observations.columns) |
24
|
|
|
|
25
|
|
|
@classmethod |
26
|
|
|
def nb_rows(cls, data): |
27
|
|
|
print('\n------ DEBUG NB ROWS PDTabularRetrieverDelegate DATA TYPE', type(data), ' ------\n') |
28
|
|
|
return len(data.observations) |
29
|
|
|
|
30
|
|
|
@classmethod |
31
|
|
|
def get_numerical_attributes(cls, data): |
32
|
|
|
return data.observations._get_numeric_data().columns.values |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class PDTabularIteratorDelegate(EngineTabularIterator): |
36
|
|
|
"""The observation object is the same as the one your return from 'from_json_lines'""" |
37
|
|
|
|
38
|
|
|
@classmethod |
39
|
|
|
def columnnames(cls, data): |
40
|
|
|
return list(data.observations.columns) |
41
|
|
|
|
42
|
|
|
@classmethod |
43
|
|
|
def iterrows(cls, data): |
44
|
|
|
return iter(data.observations.iterrows()) |
45
|
|
|
|
46
|
|
|
@classmethod |
47
|
|
|
def itercolumns(cls, data): |
48
|
|
|
return iter(data.observations[column] for column in data.observations.columns) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
class PDTabularMutatorDelegate(EngineTabularMutator): |
52
|
|
|
|
53
|
|
|
@classmethod |
54
|
|
|
def add_column(cls, datapoints, values, new_attribute, **kwargs): |
55
|
|
|
datapoints.observations[new_attribute] = values |
56
|
|
|
|