python-table-processor 0.3.1__tar.gz → 0.3.3__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.1 → python_table_processor-0.3.3}/PKG-INFO +1 -1
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/pyproject.toml +1 -1
- python_table_processor-0.3.3/table_processor/__init__.py +2 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/actions.py +64 -14
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/config.py +0 -1
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/convert.py +0 -13
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/types.py +10 -1
- python_table_processor-0.3.1/table_processor/__init__.py +0 -2
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/LICENSE +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/README.md +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/cli.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/commands/convert_tables.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/commands/merge_tables.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/constants.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/assign_id.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/flatten_row.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/get_nested_field_value.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/nest_row.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/search_column_value.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/set_flat_field_value.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/set_nested_field_value.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/functions/set_row_value.py +0 -0
- {python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/merge.py +0 -0
{python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/actions.py
RENAMED
|
@@ -28,6 +28,7 @@ from . types import (
|
|
|
28
28
|
AssignConstantConfig,
|
|
29
29
|
AssignFormatConfig,
|
|
30
30
|
AssignIdConfig,
|
|
31
|
+
AssignLengthConfig,
|
|
31
32
|
FilterConfig,
|
|
32
33
|
GlobalStatus,
|
|
33
34
|
JoinConfig,
|
|
@@ -140,6 +141,12 @@ def setup_actions_with_args(
|
|
|
140
141
|
reverse = reverse,
|
|
141
142
|
))
|
|
142
143
|
continue
|
|
144
|
+
if action_name == 'assign-length':
|
|
145
|
+
config.actions.append(AssignLengthConfig(
|
|
146
|
+
target = target,
|
|
147
|
+
source = source,
|
|
148
|
+
))
|
|
149
|
+
continue
|
|
143
150
|
if action_name == 'filter-empty':
|
|
144
151
|
config.actions.append(FilterConfig(
|
|
145
152
|
field = target,
|
|
@@ -170,15 +177,26 @@ def setup_actions_with_args(
|
|
|
170
177
|
if action_name == 'parse':
|
|
171
178
|
as_type = options.get('as', 'literal')
|
|
172
179
|
required = options.get('required', False)
|
|
173
|
-
if as_type
|
|
180
|
+
if as_type in ['boolean']:
|
|
181
|
+
as_type = 'bool'
|
|
182
|
+
if as_type not in ['bool', 'json', 'literal']:
|
|
174
183
|
raise ValueError(
|
|
175
184
|
f'Unsupported as type: {as_type}'
|
|
176
185
|
)
|
|
186
|
+
assign_default = False
|
|
187
|
+
default_value = None
|
|
188
|
+
if 'default' in options:
|
|
189
|
+
assign_default = True
|
|
190
|
+
default_value = options['default']
|
|
191
|
+
if default_value in ['None', 'none', 'Null', 'null']:
|
|
192
|
+
default_value = None
|
|
177
193
|
config.actions.append(ParseConfig(
|
|
178
194
|
target = target,
|
|
179
195
|
source = source,
|
|
180
196
|
as_type = as_type,
|
|
181
197
|
required = required,
|
|
198
|
+
assign_default = assign_default,
|
|
199
|
+
default_value = default_value,
|
|
182
200
|
))
|
|
183
201
|
continue
|
|
184
202
|
if action_name == 'parse-json':
|
|
@@ -303,6 +321,8 @@ def do_action(
|
|
|
303
321
|
return assign_format(row, action)
|
|
304
322
|
if isinstance(action, AssignIdConfig):
|
|
305
323
|
return assign_id(status.id_context_map, row, action)
|
|
324
|
+
if isinstance(action, AssignLengthConfig):
|
|
325
|
+
return assign_length(row, action)
|
|
306
326
|
if isinstance(action, FilterConfig):
|
|
307
327
|
if filter_row(row, action):
|
|
308
328
|
return row
|
|
@@ -590,27 +610,48 @@ def parse(
|
|
|
590
610
|
f'Required field not found, field: {config.source}'
|
|
591
611
|
)
|
|
592
612
|
if found:
|
|
593
|
-
if
|
|
594
|
-
|
|
595
|
-
|
|
613
|
+
if config.as_type == 'literal':
|
|
614
|
+
try:
|
|
615
|
+
if type(value) is str:
|
|
596
616
|
parsed = ast.literal_eval(value)
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
617
|
+
else:
|
|
618
|
+
parsed = value
|
|
619
|
+
except:
|
|
620
|
+
raise ValueError(
|
|
621
|
+
f'Failed to parse literal: {value}'
|
|
622
|
+
)
|
|
623
|
+
elif config.as_type == 'json':
|
|
624
|
+
try:
|
|
625
|
+
if type(value) is str:
|
|
603
626
|
parsed = json.loads(value)
|
|
604
|
-
|
|
627
|
+
else:
|
|
628
|
+
parsed = value
|
|
629
|
+
except:
|
|
630
|
+
raise ValueError(
|
|
631
|
+
f'Failed to parse JSON: {value}'
|
|
632
|
+
)
|
|
633
|
+
elif config.as_type == 'bool':
|
|
634
|
+
if config.assign_default and value in [None, '']:
|
|
635
|
+
value = config.default_value
|
|
636
|
+
if type(value) is bool:
|
|
637
|
+
parsed = value
|
|
638
|
+
elif type(value) is str:
|
|
639
|
+
if value.lower() in ['true', 'yes', 'on', '1']:
|
|
640
|
+
parsed = True
|
|
641
|
+
elif value.lower() in ['false', 'no', 'off', '0']:
|
|
642
|
+
parsed = False
|
|
643
|
+
else:
|
|
605
644
|
raise ValueError(
|
|
606
|
-
f'Failed to parse
|
|
645
|
+
f'Failed to parse bool: {value}'
|
|
607
646
|
)
|
|
608
647
|
else:
|
|
609
648
|
raise ValueError(
|
|
610
|
-
f'
|
|
649
|
+
f'Failed to parse bool: {value}'
|
|
611
650
|
)
|
|
612
651
|
else:
|
|
613
|
-
|
|
652
|
+
raise ValueError(
|
|
653
|
+
f'Unsupported as type: {config.as_type}'
|
|
654
|
+
)
|
|
614
655
|
set_row_staging_value(row, config.target, parsed)
|
|
615
656
|
return row
|
|
616
657
|
|
|
@@ -635,3 +676,12 @@ def push_field(
|
|
|
635
676
|
set_row_staging_value(row, config.target, array)
|
|
636
677
|
array.append(source_value)
|
|
637
678
|
return row
|
|
679
|
+
|
|
680
|
+
def assign_length(
|
|
681
|
+
row: Row,
|
|
682
|
+
config: AssignLengthConfig,
|
|
683
|
+
):
|
|
684
|
+
value, found = search_column_value(row.nested, config.source)
|
|
685
|
+
if found:
|
|
686
|
+
set_row_staging_value(row, config.target, len(value))
|
|
687
|
+
return row
|
{python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/config.py
RENAMED
|
@@ -34,7 +34,6 @@ class AssignArrayConfig:
|
|
|
34
34
|
@dataclasses.dataclass
|
|
35
35
|
class ProcessConfig:
|
|
36
36
|
assign_array: Mapping[str, list[AssignArrayConfig]] = dataclasses.field(default_factory=OrderedDict)
|
|
37
|
-
assign_length: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
|
|
38
37
|
|
|
39
38
|
def __setitem__(self, key, value):
|
|
40
39
|
setattr(self, key, value)
|
{python_table_processor-0.3.1 → python_table_processor-0.3.3}/table_processor/core/convert.py
RENAMED
|
@@ -263,17 +263,6 @@ def search_column_value_from_nested(
|
|
|
263
263
|
return None, False
|
|
264
264
|
|
|
265
265
|
|
|
266
|
-
def assign_length(
|
|
267
|
-
row: OrderedDict,
|
|
268
|
-
dict_fields: OrderedDict,
|
|
269
|
-
):
|
|
270
|
-
new_row = OrderedDict(row)
|
|
271
|
-
for key, field in dict_fields.items():
|
|
272
|
-
value, found = search_column_value(row, field)
|
|
273
|
-
if found:
|
|
274
|
-
new_row[f'{STAGING_FIELD}.{key}'] = len(value)
|
|
275
|
-
return new_row
|
|
276
|
-
|
|
277
266
|
def convert(
|
|
278
267
|
input_files: list[str],
|
|
279
268
|
output_file: str | None = None,
|
|
@@ -348,8 +337,6 @@ def convert(
|
|
|
348
337
|
set_row_staging_value(row, INPUT_FIELD, orig_row.nested)
|
|
349
338
|
if config.process.assign_array:
|
|
350
339
|
row.flat= assign_array(row.flat, config.process.assign_array)
|
|
351
|
-
if config.process.assign_length:
|
|
352
|
-
row.flat = assign_length(row.flat, config.process.assign_length)
|
|
353
340
|
if config.actions:
|
|
354
341
|
try:
|
|
355
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
|
|
@@ -69,8 +74,12 @@ class OmitConfig:
|
|
|
69
74
|
class ParseConfig:
|
|
70
75
|
target: str
|
|
71
76
|
source: str
|
|
72
|
-
as_type: Literal[
|
|
77
|
+
as_type: Literal[
|
|
78
|
+
'bool', 'json', 'literal'
|
|
79
|
+
]
|
|
73
80
|
required: bool = False
|
|
81
|
+
assign_default: bool = False
|
|
82
|
+
default_value: Any = None
|
|
74
83
|
|
|
75
84
|
@dataclasses.dataclass
|
|
76
85
|
class PickConfig:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_table_processor-0.3.1 → python_table_processor-0.3.3}/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
|