python-table-processor 0.3.1__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.
Files changed (23) hide show
  1. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/PKG-INFO +1 -1
  2. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/pyproject.toml +1 -1
  3. python_table_processor-0.3.2/table_processor/__init__.py +2 -0
  4. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/actions.py +18 -0
  5. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/config.py +0 -1
  6. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/convert.py +0 -13
  7. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/types.py +5 -0
  8. python_table_processor-0.3.1/table_processor/__init__.py +0 -2
  9. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/LICENSE +0 -0
  10. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/README.md +0 -0
  11. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/cli.py +0 -0
  12. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/commands/convert_tables.py +0 -0
  13. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/commands/merge_tables.py +0 -0
  14. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/constants.py +0 -0
  15. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/assign_id.py +0 -0
  16. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/flatten_row.py +0 -0
  17. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/get_nested_field_value.py +0 -0
  18. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/nest_row.py +0 -0
  19. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/search_column_value.py +0 -0
  20. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/set_flat_field_value.py +0 -0
  21. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/set_nested_field_value.py +0 -0
  22. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/table_processor/core/functions/set_row_value.py +0 -0
  23. {python_table_processor-0.3.1 → python_table_processor-0.3.2}/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.1
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-table-processor"
3
- version = "0.3.1"
3
+ version = "0.3.2"
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.2"
2
+ __version_tuple__ = (0, 3, 2)
@@ -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,
@@ -303,6 +310,8 @@ def do_action(
303
310
  return assign_format(row, action)
304
311
  if isinstance(action, AssignIdConfig):
305
312
  return assign_id(status.id_context_map, row, action)
313
+ if isinstance(action, AssignLengthConfig):
314
+ return assign_length(row, action)
306
315
  if isinstance(action, FilterConfig):
307
316
  if filter_row(row, action):
308
317
  return row
@@ -635,3 +644,12 @@ def push_field(
635
644
  set_row_staging_value(row, config.target, array)
636
645
  array.append(source_value)
637
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
@@ -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)
@@ -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
@@ -1,2 +0,0 @@
1
- __version__ = "0.3.1"
2
- __version_tuple__ = (0, 3, 1)