python-table-processor 0.3.0__tar.gz → 0.3.1__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.
Files changed (23) hide show
  1. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/PKG-INFO +1 -1
  2. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/pyproject.toml +1 -1
  3. python_table_processor-0.3.1/table_processor/__init__.py +2 -0
  4. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/actions.py +33 -0
  5. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/config.py +0 -7
  6. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/convert.py +0 -25
  7. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/types.py +6 -0
  8. python_table_processor-0.3.0/table_processor/__init__.py +0 -2
  9. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/LICENSE +0 -0
  10. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/README.md +0 -0
  11. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/cli.py +0 -0
  12. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/commands/convert_tables.py +0 -0
  13. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/commands/merge_tables.py +0 -0
  14. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/constants.py +0 -0
  15. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/assign_id.py +0 -0
  16. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/flatten_row.py +0 -0
  17. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/get_nested_field_value.py +0 -0
  18. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/nest_row.py +0 -0
  19. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/search_column_value.py +0 -0
  20. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/set_flat_field_value.py +0 -0
  21. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/set_nested_field_value.py +0 -0
  22. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/functions/set_row_value.py +0 -0
  23. {python_table_processor-0.3.0 → python_table_processor-0.3.1}/table_processor/core/merge.py +0 -0
@@ -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.1
4
4
  Summary: A table data processor
5
5
  Home-page: https://github.com/akivajp/python-table-processor
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-table-processor"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "A table data processor"
5
5
  authors = ["Akiva Miura <akiva.miura@gmail.com>"]
6
6
  license = "MIT"
@@ -0,0 +1,2 @@
1
+ __version__ = "0.3.1"
2
+ __version_tuple__ = (0, 3, 1)
@@ -34,6 +34,7 @@ from . types import (
34
34
  OmitConfig,
35
35
  ParseConfig,
36
36
  PickConfig,
37
+ PushConfig,
37
38
  SplitConfig,
38
39
  Row,
39
40
  )
@@ -189,6 +190,14 @@ def setup_actions_with_args(
189
190
  required = required,
190
191
  ))
191
192
  continue
193
+ if action_name == 'push':
194
+ condition = options.get('condition', None)
195
+ config.actions.append(PushConfig(
196
+ target = target,
197
+ source = source,
198
+ condition = condition,
199
+ ))
200
+ continue
192
201
  if action_name == 'split':
193
202
  delimiter = options.get('delimiter', None)
194
203
  if delimiter == '\\n':
@@ -304,6 +313,8 @@ def do_action(
304
313
  return parse(row, action)
305
314
  if isinstance(action, OmitConfig):
306
315
  return omit_field(row, action)
316
+ if isinstance(action, PushConfig):
317
+ return push_field(row, action)
307
318
  if isinstance(action, SplitConfig):
308
319
  return split_field(row, action)
309
320
  raise ValueError(
@@ -602,3 +613,25 @@ def parse(
602
613
  parsed = value
603
614
  set_row_staging_value(row, config.target, parsed)
604
615
  return row
616
+
617
+ def push_field(
618
+ row: Row,
619
+ config: PushConfig,
620
+ ):
621
+ source_value, found = search_column_value(row.nested, config.source)
622
+ do_append = False
623
+ if config.condition is None:
624
+ do_append = True
625
+ else:
626
+ condition_value, found = search_column_value(row.nested, config.condition)
627
+ if condition_value:
628
+ do_append = True
629
+ if do_append:
630
+ target_value, found = search_column_value(row.nested, config.target)
631
+ if found:
632
+ array = target_value
633
+ else:
634
+ array = []
635
+ set_row_staging_value(row, config.target, array)
636
+ array.append(source_value)
637
+ return row
@@ -31,17 +31,10 @@ 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
37
  assign_length: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
44
- push: list[PushConfig] = dataclasses.field(default_factory=list)
45
38
 
46
39
  def __setitem__(self, key, value):
47
40
  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,28 +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
266
  def assign_length(
290
267
  row: OrderedDict,
291
268
  dict_fields: OrderedDict,
@@ -371,8 +348,6 @@ def convert(
371
348
  set_row_staging_value(row, INPUT_FIELD, orig_row.nested)
372
349
  if config.process.assign_array:
373
350
  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
351
  if config.process.assign_length:
377
352
  row.flat = assign_length(row.flat, config.process.assign_length)
378
353
  if config.actions:
@@ -77,6 +77,12 @@ class PickConfig:
77
77
  target: str
78
78
  source: str
79
79
 
80
+ @dataclasses.dataclass
81
+ class PushConfig:
82
+ target: str
83
+ source: str
84
+ condition: str | None = None
85
+
80
86
  @dataclasses.dataclass
81
87
  class SplitConfig:
82
88
  target: str
@@ -1,2 +0,0 @@
1
- __version__ = "0.3.0"
2
- __version_tuple__ = (0, 3, 0)