python-table-processor 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-table-processor
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A table data processor
5
5
  Home-page: https://github.com/akivajp/python-table-processor
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
- table_processor/__init__.py,sha256=gybnWB0ziz1cPSSQQek-Mj66Zh8ogh_WyQsnqrNmZ3g,52
1
+ table_processor/__init__.py,sha256=TQqqDugVb2WjmgqPXyxUA42oi3QOxyPDqpr09kjKGlk,52
2
2
  table_processor/cli.py,sha256=uluf_VsBzq3Ldxh3ePGseSrv8--lI7huu-6RjDaHPPg,2170
3
3
  table_processor/commands/convert_tables.py,sha256=j25KL0zRl5ikrBk73jAkKn4rPmDq7SecChZxecDpILQ,2123
4
4
  table_processor/commands/merge_tables.py,sha256=Uu-hjfPh69Of0_OZrY8sY0oscpLSdK4jwJ_t1qgfPMg,1485
5
- table_processor/core/actions.py,sha256=tZeStD07jRC_q-2r5dKXtN4wIE52JO82TTrUyHR-ias,18645
6
- table_processor/core/config.py,sha256=iiHAcJlO4RyXyrXFAd2ZRU3bJBnJIFM79AdfcEMMI5o,11903
5
+ table_processor/core/actions.py,sha256=iCBm-tj_gTxeHxPaBSILdYAe8-75XaDtsCOTJp1jGfA,20264
6
+ table_processor/core/config.py,sha256=Z1s2r3y4oQXdbDCwIY_hYzoq6VRv7Sb3oUlfBCu13Lc,11646
7
7
  table_processor/core/constants.py,sha256=w-1TxtpXywb6Qh8M4YWuzcCHUvCjy5zJYxaXC3RQS6A,158
8
- table_processor/core/convert.py,sha256=SbDMJnXuXKuZ-7PBSqWl7pVsaBOforXQlRekq4XYKbY,12536
8
+ table_processor/core/convert.py,sha256=cibzqJ5hHsfX_7qUz4kE2Gi-WH4UMqecBl3kSb4IVsY,11140
9
9
  table_processor/core/functions/assign_id.py,sha256=dA-wgZA7E01gbx8qGvo1PeMd3aq9PhMdyITzr3BKXIE,4204
10
10
  table_processor/core/functions/flatten_row.py,sha256=2l-s4YXgBM58IthpfVzd7L4EGUCekSi7ss5CaM_3MUU,686
11
11
  table_processor/core/functions/get_nested_field_value.py,sha256=vF4pH6nxR3-2bDfAvrMfHcPFNiS4MnGkXL8FdcScdIw,685
@@ -15,9 +15,9 @@ table_processor/core/functions/set_flat_field_value.py,sha256=7-BgD2yEUGyBaFaIJ1
15
15
  table_processor/core/functions/set_nested_field_value.py,sha256=csO0v_nW94q-M9bNL91xR-TLHPXDDxnLK8gN-0LLd6k,595
16
16
  table_processor/core/functions/set_row_value.py,sha256=wlF_nVGZY74XCzd6pBJJyti62m6y0s1kc5Q6uq9jn8o,641
17
17
  table_processor/core/merge.py,sha256=Yc5OV9n1xV9QtgY4srl6Susd5cOKbuYseEtYuBampDw,4672
18
- table_processor/core/types.py,sha256=pQrNtf5pt5Unn3x8WK6ZtDpMhU9r8iYRAucToZQEBh0,2391
19
- python_table_processor-0.3.0.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
- python_table_processor-0.3.0.dist-info/METADATA,sha256=7j1SD0x8oegMJFKwjnraXyMoN_WQMhIFzCCPD14yXDc,1098
21
- python_table_processor-0.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
- python_table_processor-0.3.0.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
- python_table_processor-0.3.0.dist-info/RECORD,,
18
+ table_processor/core/types.py,sha256=rxmiWsUCEBkjveO84tbMJ1kVn_P13Ywl89wDHMWEej0,2580
19
+ python_table_processor-0.3.2.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
+ python_table_processor-0.3.2.dist-info/METADATA,sha256=PCCGEqAansu5aIrmLu4eaFl3HhD2DCbDuDt2ru0-nRs,1098
21
+ python_table_processor-0.3.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
+ python_table_processor-0.3.2.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
+ python_table_processor-0.3.2.dist-info/RECORD,,
@@ -1,2 +1,2 @@
1
- __version__ = "0.3.0"
2
- __version_tuple__ = (0, 3, 0)
1
+ __version__ = "0.3.2"
2
+ __version_tuple__ = (0, 3, 2)
@@ -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
@@ -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)
@@ -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