python-table-processor 0.3.0__tar.gz → 0.3.2__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_processor-0.3.0 → python_table_processor-0.3.2}/PKG-INFO +1 -1
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/pyproject.toml +1 -1
- python_table_processor-0.3.2/table_processor/__init__.py +2 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/actions.py +51 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/config.py +0 -8
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/convert.py +0 -38
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/types.py +11 -0
- python_table_processor-0.3.0/table_processor/__init__.py +0 -2
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/LICENSE +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/README.md +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/cli.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/commands/convert_tables.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/commands/merge_tables.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/constants.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/assign_id.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/flatten_row.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/get_nested_field_value.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/nest_row.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/search_column_value.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/set_flat_field_value.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/set_nested_field_value.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/functions/set_row_value.py +0 -0
- {python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/merge.py +0 -0
{python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/actions.py
RENAMED
|
@@ -28,12 +28,14 @@ from . types import (
|
|
|
28
28
|
AssignConstantConfig,
|
|
29
29
|
AssignFormatConfig,
|
|
30
30
|
AssignIdConfig,
|
|
31
|
+
AssignLengthConfig,
|
|
31
32
|
FilterConfig,
|
|
32
33
|
GlobalStatus,
|
|
33
34
|
JoinConfig,
|
|
34
35
|
OmitConfig,
|
|
35
36
|
ParseConfig,
|
|
36
37
|
PickConfig,
|
|
38
|
+
PushConfig,
|
|
37
39
|
SplitConfig,
|
|
38
40
|
Row,
|
|
39
41
|
)
|
|
@@ -139,6 +141,12 @@ def setup_actions_with_args(
|
|
|
139
141
|
reverse = reverse,
|
|
140
142
|
))
|
|
141
143
|
continue
|
|
144
|
+
if action_name == 'assign-length':
|
|
145
|
+
config.actions.append(AssignLengthConfig(
|
|
146
|
+
target = target,
|
|
147
|
+
source = source,
|
|
148
|
+
))
|
|
149
|
+
continue
|
|
142
150
|
if action_name == 'filter-empty':
|
|
143
151
|
config.actions.append(FilterConfig(
|
|
144
152
|
field = target,
|
|
@@ -189,6 +197,14 @@ def setup_actions_with_args(
|
|
|
189
197
|
required = required,
|
|
190
198
|
))
|
|
191
199
|
continue
|
|
200
|
+
if action_name == 'push':
|
|
201
|
+
condition = options.get('condition', None)
|
|
202
|
+
config.actions.append(PushConfig(
|
|
203
|
+
target = target,
|
|
204
|
+
source = source,
|
|
205
|
+
condition = condition,
|
|
206
|
+
))
|
|
207
|
+
continue
|
|
192
208
|
if action_name == 'split':
|
|
193
209
|
delimiter = options.get('delimiter', None)
|
|
194
210
|
if delimiter == '\\n':
|
|
@@ -294,6 +310,8 @@ def do_action(
|
|
|
294
310
|
return assign_format(row, action)
|
|
295
311
|
if isinstance(action, AssignIdConfig):
|
|
296
312
|
return assign_id(status.id_context_map, row, action)
|
|
313
|
+
if isinstance(action, AssignLengthConfig):
|
|
314
|
+
return assign_length(row, action)
|
|
297
315
|
if isinstance(action, FilterConfig):
|
|
298
316
|
if filter_row(row, action):
|
|
299
317
|
return row
|
|
@@ -304,6 +322,8 @@ def do_action(
|
|
|
304
322
|
return parse(row, action)
|
|
305
323
|
if isinstance(action, OmitConfig):
|
|
306
324
|
return omit_field(row, action)
|
|
325
|
+
if isinstance(action, PushConfig):
|
|
326
|
+
return push_field(row, action)
|
|
307
327
|
if isinstance(action, SplitConfig):
|
|
308
328
|
return split_field(row, action)
|
|
309
329
|
raise ValueError(
|
|
@@ -602,3 +622,34 @@ def parse(
|
|
|
602
622
|
parsed = value
|
|
603
623
|
set_row_staging_value(row, config.target, parsed)
|
|
604
624
|
return row
|
|
625
|
+
|
|
626
|
+
def push_field(
|
|
627
|
+
row: Row,
|
|
628
|
+
config: PushConfig,
|
|
629
|
+
):
|
|
630
|
+
source_value, found = search_column_value(row.nested, config.source)
|
|
631
|
+
do_append = False
|
|
632
|
+
if config.condition is None:
|
|
633
|
+
do_append = True
|
|
634
|
+
else:
|
|
635
|
+
condition_value, found = search_column_value(row.nested, config.condition)
|
|
636
|
+
if condition_value:
|
|
637
|
+
do_append = True
|
|
638
|
+
if do_append:
|
|
639
|
+
target_value, found = search_column_value(row.nested, config.target)
|
|
640
|
+
if found:
|
|
641
|
+
array = target_value
|
|
642
|
+
else:
|
|
643
|
+
array = []
|
|
644
|
+
set_row_staging_value(row, config.target, array)
|
|
645
|
+
array.append(source_value)
|
|
646
|
+
return row
|
|
647
|
+
|
|
648
|
+
def assign_length(
|
|
649
|
+
row: Row,
|
|
650
|
+
config: AssignLengthConfig,
|
|
651
|
+
):
|
|
652
|
+
value, found = search_column_value(row.nested, config.source)
|
|
653
|
+
if found:
|
|
654
|
+
set_row_staging_value(row, config.target, len(value))
|
|
655
|
+
return row
|
{python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/config.py
RENAMED
|
@@ -31,17 +31,9 @@ class AssignArrayConfig:
|
|
|
31
31
|
field: str
|
|
32
32
|
optional: bool = True
|
|
33
33
|
|
|
34
|
-
@dataclasses.dataclass
|
|
35
|
-
class PushConfig:
|
|
36
|
-
target: str
|
|
37
|
-
source: str
|
|
38
|
-
condition: str | None = None
|
|
39
|
-
|
|
40
34
|
@dataclasses.dataclass
|
|
41
35
|
class ProcessConfig:
|
|
42
36
|
assign_array: Mapping[str, list[AssignArrayConfig]] = dataclasses.field(default_factory=OrderedDict)
|
|
43
|
-
assign_length: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
44
|
-
push: list[PushConfig] = dataclasses.field(default_factory=list)
|
|
45
37
|
|
|
46
38
|
def __setitem__(self, key, value):
|
|
47
39
|
setattr(self, key, value)
|
{python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/convert.py
RENAMED
|
@@ -20,7 +20,6 @@ import pandas as pd
|
|
|
20
20
|
|
|
21
21
|
from . config import (
|
|
22
22
|
AssignArrayConfig,
|
|
23
|
-
PushConfig,
|
|
24
23
|
setup_config,
|
|
25
24
|
setup_pick_with_args,
|
|
26
25
|
)
|
|
@@ -264,39 +263,6 @@ def search_column_value_from_nested(
|
|
|
264
263
|
return None, False
|
|
265
264
|
|
|
266
265
|
|
|
267
|
-
def push_fields(
|
|
268
|
-
row: OrderedDict,
|
|
269
|
-
list_config: list[PushConfig],
|
|
270
|
-
):
|
|
271
|
-
nested_row = nest(row)
|
|
272
|
-
for config in list_config:
|
|
273
|
-
target_value, found = search_column_value_from_nested(nested_row, config.target)
|
|
274
|
-
if found:
|
|
275
|
-
array = target_value
|
|
276
|
-
else:
|
|
277
|
-
array = []
|
|
278
|
-
#set_field_value(nested_row, f'{STAGING_FIELD}.{config.target}', array)
|
|
279
|
-
set_row_staging_value(nested_row, config.target, array)
|
|
280
|
-
source_value, found = search_column_value_from_nested(nested_row, config.source)
|
|
281
|
-
if config.condition is None:
|
|
282
|
-
array.append(source_value)
|
|
283
|
-
continue
|
|
284
|
-
condition_value, found = search_column_value_from_nested(nested_row, config.condition)
|
|
285
|
-
if condition_value:
|
|
286
|
-
array.append(source_value)
|
|
287
|
-
return flatten_row(nested_row)
|
|
288
|
-
|
|
289
|
-
def assign_length(
|
|
290
|
-
row: OrderedDict,
|
|
291
|
-
dict_fields: OrderedDict,
|
|
292
|
-
):
|
|
293
|
-
new_row = OrderedDict(row)
|
|
294
|
-
for key, field in dict_fields.items():
|
|
295
|
-
value, found = search_column_value(row, field)
|
|
296
|
-
if found:
|
|
297
|
-
new_row[f'{STAGING_FIELD}.{key}'] = len(value)
|
|
298
|
-
return new_row
|
|
299
|
-
|
|
300
266
|
def convert(
|
|
301
267
|
input_files: list[str],
|
|
302
268
|
output_file: str | None = None,
|
|
@@ -371,10 +337,6 @@ def convert(
|
|
|
371
337
|
set_row_staging_value(row, INPUT_FIELD, orig_row.nested)
|
|
372
338
|
if config.process.assign_array:
|
|
373
339
|
row.flat= assign_array(row.flat, config.process.assign_array)
|
|
374
|
-
if config.process.push:
|
|
375
|
-
row.flat = push_fields(row.flat, config.process.push)
|
|
376
|
-
if config.process.assign_length:
|
|
377
|
-
row.flat = assign_length(row.flat, config.process.assign_length)
|
|
378
340
|
if config.actions:
|
|
379
341
|
try:
|
|
380
342
|
new_row = do_actions(global_status, row, config.actions)
|
|
@@ -46,6 +46,11 @@ class AssignIdConfig:
|
|
|
46
46
|
context: list[str] | None = None
|
|
47
47
|
reverse: bool = False
|
|
48
48
|
|
|
49
|
+
@dataclasses.dataclass
|
|
50
|
+
class AssignLengthConfig:
|
|
51
|
+
target: str
|
|
52
|
+
source: str
|
|
53
|
+
|
|
49
54
|
@dataclasses.dataclass
|
|
50
55
|
class FilterConfig:
|
|
51
56
|
field: str
|
|
@@ -77,6 +82,12 @@ class PickConfig:
|
|
|
77
82
|
target: str
|
|
78
83
|
source: str
|
|
79
84
|
|
|
85
|
+
@dataclasses.dataclass
|
|
86
|
+
class PushConfig:
|
|
87
|
+
target: str
|
|
88
|
+
source: str
|
|
89
|
+
condition: str | None = None
|
|
90
|
+
|
|
80
91
|
@dataclasses.dataclass
|
|
81
92
|
class SplitConfig:
|
|
82
93
|
target: str
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_table_processor-0.3.0 → python_table_processor-0.3.2}/table_processor/core/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|