-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdataset_interface.py
More file actions
270 lines (229 loc) · 6.09 KB
/
dataset_interface.py
File metadata and controls
270 lines (229 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
from abc import ABC, abstractmethod
from typing import Union, List
class DatasetInterface(ABC):
@property
@abstractmethod
def data(self):
"""
Stores the underlying data for the dataset
"""
@property
@abstractmethod
def empty(self):
"""
Returns whether or not the underlying dataframe is empty
"""
@property
@abstractmethod
def columns(self):
"""
Stores the columns of the underlying dataset
"""
@classmethod
@abstractmethod
def from_dict(cls, data: dict, **kwargs):
"""
Create the underlying dataset from provided dictionary data
"""
@classmethod
@abstractmethod
def from_records(cls, data: List[dict], **kwargs):
"""
Create the underlying dataset from provided list of records
"""
@classmethod
@abstractmethod
def get_series_values(cls, series) -> list:
"""
Returns the values for a series.
"""
@abstractmethod
def __getitem__(self, item: str):
"""
Access dataset column by name
"""
@abstractmethod
def __setitem__(self, key: str, data):
"""
Set value of a dataset column
"""
@abstractmethod
def __len__(self):
"""
Get length of dataset
"""
@abstractmethod
def __contains__(self, item: str) -> bool:
"""
Return true if item is in dataset
"""
@abstractmethod
def get(self, column: str, default=None):
"""
Return column if column is in dataset, else return default
"""
@abstractmethod
def groupby(self, by: List[str], **kwargs):
"""
Group dataframe by list of columns.
"""
@abstractmethod
def concat(
self, other: Union["DatasetInterface", List["DatasetInterface"]], **kwargs
):
"""
Concat two datasets
"""
@abstractmethod
def merge(self, other: "DatasetInterface", **kwargs):
"""
merge two datasets
"""
@abstractmethod
def apply(self, func, **kwargs):
"""
Apply a function to a dataset
"""
@abstractmethod
def iterrows(self):
"""
Return iterator over all dataset rows
"""
@classmethod
@abstractmethod
def is_series(cls, data) -> bool:
"""
Return true if the data is a series compatible with the underlying dataset
"""
@abstractmethod
def convert_to_series(self, data):
"""
Converts list like data to a series corresponding with the underlying dataset
"""
@abstractmethod
def get_series_from_value(self, value):
"""
Create a series of a single value
"""
@abstractmethod
def rename(self, index=None, columns=None, inplace=True):
"""
Rename columns or index labels.
"""
@abstractmethod
def drop(self, labels=None, axis=0, columns=None, errors="raise"):
"""
Drop specified labels from rows or columns.
"""
@abstractmethod
def melt(
self,
id_vars=None,
value_vars=None,
var_name=None,
value_name="value",
col_level=None,
):
"""
Unpivots a DataFrame from wide format to long format,
optionally leaving identifier variables set.
"""
@abstractmethod
def set_index(self, keys, **kwargs):
"""
Wrapper for DataFrame set_index method
"""
@abstractmethod
def filter(self, **kwargs):
"""
Wrapper for DataFrame filter method
"""
@abstractmethod
def len(self) -> int:
"""
Return the length of the dataset
"""
@abstractmethod
def assign(self, **kwargs):
"""
Assign new columns to the dataset.
This method should return a new instance of the dataset with the new columns added.
"""
@abstractmethod
def copy(self) -> "DatasetInterface":
"""
Return a new instance of the dataset with the same data
"""
@abstractmethod
def get_error_rows(self, results):
"""
Returns a pandas dataframe with all errors found in the dataset. Limited to 1000
"""
@abstractmethod
def equals(self) -> bool:
"""
Determine if two datasets are equal
"""
@abstractmethod
def where(cond, other, **kwargs):
"""
Wrapper for dataframe where function
"""
@abstractmethod
def sort_values(self, by, **kwargs):
"""
Sort the dataframe by the provided columns
"""
@abstractmethod
def is_column_sorted_within(self, group, column):
"""
Returns true if the column is sorted within each grouping otherwise false
"""
@abstractmethod
def min(self, *args, **kwargs):
"""
Return the minimum of the values over the requested axis.
"""
@abstractmethod
def reset_index(self, drop=False, **kwargs):
"""
Reset the index of the dataset.
"""
@abstractmethod
def fillna(
self,
value=None,
axis=None,
inplace=False,
limit=None,
):
"""
Fill NA/NaN values using the specified method.
"""
@abstractmethod
def get_grouped_size(self, by, **kwargs):
"""
Returns a dataframe containing the sizes of each group in
the dataframe.
"""
@abstractmethod
def to_dict(self, **kwargs) -> dict:
"""
Convert the dataset to a dictionary.
"""
@abstractmethod
def items(self, **kwargs):
"""
Convert the dataset to dictionary items.
Returns a view object displaying a list of (key, value) tuple pairs.
"""
@abstractmethod
def keys(self, **kwargs):
"""
Returns a view object containing the keys in the dataset dictionary.
"""
@abstractmethod
def values(self, **kwargs):
"""
Returns a view object containing the values in the dataset dictionary.
"""