python-table-converter 0.2.10__tar.gz → 0.2.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/PKG-INFO +1 -1
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/pyproject.toml +1 -1
- python_table_converter-0.2.12/table_converter/__init__.py +2 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/config.py +96 -5
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/convert.py +28 -12
- python_table_converter-0.2.10/table_converter/__init__.py +0 -2
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/LICENSE +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/README.md +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/cli.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/commands/convert_tables.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/constants.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/functions/assign_id.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/functions/flatten.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/functions/get_field_value.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/functions/search_column_value.py +0 -0
- {python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/functions/set_field_value.py +0 -0
{python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/config.py
RENAMED
|
@@ -24,8 +24,14 @@ class AssignIdConfig:
|
|
|
24
24
|
@dataclasses.dataclass
|
|
25
25
|
class FilterConfig:
|
|
26
26
|
field: str
|
|
27
|
-
operator: Literal['==', '!=', '>', '>=', '<', '<=']
|
|
28
|
-
value: str
|
|
27
|
+
operator: Literal['==', '!=', '>', '>=', '<', '<=', 'not-in']
|
|
28
|
+
#value: str
|
|
29
|
+
value: str | list[str]
|
|
30
|
+
|
|
31
|
+
@dataclasses.dataclass
|
|
32
|
+
class SplitConfig:
|
|
33
|
+
field: str
|
|
34
|
+
delimiter: str
|
|
29
35
|
|
|
30
36
|
@dataclasses.dataclass
|
|
31
37
|
class ProcessConfig:
|
|
@@ -35,7 +41,8 @@ class ProcessConfig:
|
|
|
35
41
|
#filter_eq: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
36
42
|
filter: list[FilterConfig] = dataclasses.field(default_factory=list)
|
|
37
43
|
omit_fields: list[str] = dataclasses.field(default_factory=list)
|
|
38
|
-
split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
44
|
+
#split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
45
|
+
split: Mapping[str, SplitConfig] = dataclasses.field(default_factory=OrderedDict)
|
|
39
46
|
|
|
40
47
|
def __setitem__(self, key, value):
|
|
41
48
|
setattr(self, key, value)
|
|
@@ -76,13 +83,13 @@ def setup_process_config(
|
|
|
76
83
|
for process_key in [
|
|
77
84
|
'assign_constants',
|
|
78
85
|
'assign_formats',
|
|
79
|
-
'filter_eq',
|
|
80
|
-
'split_by_newline',
|
|
81
86
|
]:
|
|
82
87
|
dict_subprocess = dict_process.get(process_key)
|
|
83
88
|
if isinstance(dict_subprocess, Mapping):
|
|
84
89
|
config.process[process_key] = flatten(loaded['process'][process_key])
|
|
85
90
|
setup_process_assign_ids_config(config, dict_process)
|
|
91
|
+
setup_process_filter_config(config, dict_process)
|
|
92
|
+
setup_process_split_config(config, dict_process)
|
|
86
93
|
|
|
87
94
|
def setup_process_assign_ids_config(
|
|
88
95
|
config: Config,
|
|
@@ -120,3 +127,87 @@ def setup_process_assign_ids_config(
|
|
|
120
127
|
raise ValueError(
|
|
121
128
|
f'Unsupported assign_ids value type: {type(value)}'
|
|
122
129
|
)
|
|
130
|
+
|
|
131
|
+
def setup_process_filter_config(
|
|
132
|
+
config: Config,
|
|
133
|
+
dict_process: Mapping,
|
|
134
|
+
):
|
|
135
|
+
list_subprocess = dict_process.get('filter')
|
|
136
|
+
if not isinstance(list_subprocess, list):
|
|
137
|
+
raise ValueError(
|
|
138
|
+
'Filter must be a list.'
|
|
139
|
+
)
|
|
140
|
+
for item in list_subprocess:
|
|
141
|
+
if isinstance(item, Mapping):
|
|
142
|
+
field = item.get('field')
|
|
143
|
+
if not field:
|
|
144
|
+
ic.enable()
|
|
145
|
+
ic(item)
|
|
146
|
+
ic(item.get('field'))
|
|
147
|
+
raise ValueError(
|
|
148
|
+
'Field is required for filter.'
|
|
149
|
+
)
|
|
150
|
+
operator = item.get('operator')
|
|
151
|
+
if not operator:
|
|
152
|
+
ic.enable()
|
|
153
|
+
ic(item)
|
|
154
|
+
ic(item.get('operator'))
|
|
155
|
+
raise ValueError(
|
|
156
|
+
'Operator is required for filter.'
|
|
157
|
+
)
|
|
158
|
+
value = item.get('value')
|
|
159
|
+
if not value:
|
|
160
|
+
ic.enable()
|
|
161
|
+
ic(item)
|
|
162
|
+
ic(item.get('value'))
|
|
163
|
+
raise ValueError(
|
|
164
|
+
'Value is required for filter.'
|
|
165
|
+
)
|
|
166
|
+
config.process.filter.append(FilterConfig(
|
|
167
|
+
field = field,
|
|
168
|
+
operator = operator,
|
|
169
|
+
value = value,
|
|
170
|
+
))
|
|
171
|
+
else:
|
|
172
|
+
ic.enable()
|
|
173
|
+
ic(item)
|
|
174
|
+
ic(type(item))
|
|
175
|
+
raise ValueError(
|
|
176
|
+
f'Unsupported filter item type: {type(item)}'
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
def setup_process_split_config(
|
|
180
|
+
config: Config,
|
|
181
|
+
dict_process: Mapping,
|
|
182
|
+
):
|
|
183
|
+
dict_subprocess = dict_process.get('split')
|
|
184
|
+
if isinstance(dict_subprocess, Mapping):
|
|
185
|
+
for key, value in dict_subprocess.items():
|
|
186
|
+
if isinstance(value, Mapping):
|
|
187
|
+
field = value.get('field')
|
|
188
|
+
if not field:
|
|
189
|
+
ic.enable()
|
|
190
|
+
ic(value)
|
|
191
|
+
ic(value.get('field'))
|
|
192
|
+
raise ValueError(
|
|
193
|
+
'Field is required for split.'
|
|
194
|
+
)
|
|
195
|
+
delimiter = value.get('delimiter')
|
|
196
|
+
if not delimiter:
|
|
197
|
+
ic.enable()
|
|
198
|
+
ic(value)
|
|
199
|
+
ic(value.get('delimiter'))
|
|
200
|
+
raise ValueError(
|
|
201
|
+
'Delimiter is required for split.'
|
|
202
|
+
)
|
|
203
|
+
config.process.split[key] = SplitConfig(
|
|
204
|
+
field = field,
|
|
205
|
+
delimiter = delimiter,
|
|
206
|
+
)
|
|
207
|
+
else:
|
|
208
|
+
ic.enable()
|
|
209
|
+
ic(value)
|
|
210
|
+
ic(type(value))
|
|
211
|
+
raise ValueError(
|
|
212
|
+
f'Unsupported assign_ids value type: {type(value)}'
|
|
213
|
+
)
|
{python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/convert.py
RENAMED
|
@@ -16,6 +16,7 @@ import pandas as pd
|
|
|
16
16
|
|
|
17
17
|
from . config import (
|
|
18
18
|
FilterConfig,
|
|
19
|
+
SplitConfig,
|
|
19
20
|
setup_config,
|
|
20
21
|
)
|
|
21
22
|
from . constants import (
|
|
@@ -193,19 +194,22 @@ def remap_columns(
|
|
|
193
194
|
new_row[column] = row[column]
|
|
194
195
|
return new_row
|
|
195
196
|
|
|
196
|
-
def
|
|
197
|
+
def split_fields(
|
|
197
198
|
row: OrderedDict,
|
|
198
|
-
|
|
199
|
+
dict_config: list[SplitConfig],
|
|
199
200
|
):
|
|
200
201
|
new_row = OrderedDict(row)
|
|
201
|
-
for
|
|
202
|
-
value, found = search_column_value(row,
|
|
202
|
+
for dst, config in dict_config.items():
|
|
203
|
+
value, found = search_column_value(row, config.field)
|
|
203
204
|
if found:
|
|
204
205
|
if isinstance(value, str):
|
|
205
|
-
new_value = value.split(
|
|
206
|
-
|
|
206
|
+
new_value = value.split(config.delimiter)
|
|
207
|
+
new_value = list(filter(None, new_value))
|
|
208
|
+
if not new_value:
|
|
209
|
+
ic(dst, config, value)
|
|
210
|
+
new_row[f'{STAGING_FIELD}.{dst}'] = new_value
|
|
207
211
|
else:
|
|
208
|
-
new_row[f'{STAGING_FIELD}.{
|
|
212
|
+
new_row[f'{STAGING_FIELD}.{dst}'] = value
|
|
209
213
|
return new_row
|
|
210
214
|
|
|
211
215
|
def filter_row(
|
|
@@ -217,11 +221,19 @@ def filter_row(
|
|
|
217
221
|
if config.operator == '==':
|
|
218
222
|
if not found:
|
|
219
223
|
return False
|
|
220
|
-
if str(value) != str(config.value):
|
|
224
|
+
if value != config.value and str(value) != str(config.value):
|
|
221
225
|
return False
|
|
222
226
|
elif config.operator == '!=':
|
|
223
|
-
if str(value) == str(config.value):
|
|
227
|
+
if str(value) == str(config.value) or value == config.value:
|
|
224
228
|
return False
|
|
229
|
+
elif config.operator == 'not-in':
|
|
230
|
+
if isinstance(config.value, list):
|
|
231
|
+
if value in config.value:
|
|
232
|
+
return False
|
|
233
|
+
if str(value) in config.value:
|
|
234
|
+
return False
|
|
235
|
+
else:
|
|
236
|
+
raise ValueError(f'Unsupported filter value type: type{config.value}')
|
|
225
237
|
else:
|
|
226
238
|
raise ValueError(f'Unsupported operator: {config.operator}')
|
|
227
239
|
return True
|
|
@@ -275,7 +287,11 @@ def convert(
|
|
|
275
287
|
for field in fields:
|
|
276
288
|
if '=' in field:
|
|
277
289
|
dst, src = field.split('=')
|
|
278
|
-
config.process.split_by_newline[dst] = src
|
|
290
|
+
#config.process.split_by_newline[dst] = src
|
|
291
|
+
config.process.split[dst] = SplitConfig(
|
|
292
|
+
field = src,
|
|
293
|
+
delimiter = '\n',
|
|
294
|
+
)
|
|
279
295
|
else:
|
|
280
296
|
raise ValueError(f'Invalid split by newline: {field}')
|
|
281
297
|
if str_filters:
|
|
@@ -339,8 +355,8 @@ def convert(
|
|
|
339
355
|
new_flat_row = map_constants(new_flat_row, config.process.assign_constants)
|
|
340
356
|
if config.map:
|
|
341
357
|
new_flat_row = remap_columns(new_flat_row, config.map)
|
|
342
|
-
if config.process.
|
|
343
|
-
new_flat_row =
|
|
358
|
+
if config.process.split:
|
|
359
|
+
new_flat_row = split_fields(new_flat_row, config.process.split)
|
|
344
360
|
if config.process.assign_ids:
|
|
345
361
|
new_flat_row = assign_id(new_flat_row, config.process.assign_ids, id_context_map)
|
|
346
362
|
if config.process.assign_formats:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_table_converter-0.2.10 → python_table_converter-0.2.12}/table_converter/core/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|