python-table-processor 0.3.6__tar.gz → 0.3.7__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 (24) hide show
  1. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/PKG-INFO +1 -1
  2. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/pyproject.toml +1 -1
  3. python_table_processor-0.3.7/table_processor/__init__.py +2 -0
  4. python_table_processor-0.3.7/table_processor/core/functions/set_nested_field_value.py +41 -0
  5. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/merge.py +1 -3
  6. python_table_processor-0.3.6/table_processor/__init__.py +0 -2
  7. python_table_processor-0.3.6/table_processor/core/functions/set_nested_field_value.py +0 -24
  8. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/LICENSE +0 -0
  9. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/README.md +0 -0
  10. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/cli.py +0 -0
  11. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/commands/convert_tables.py +0 -0
  12. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/commands/merge_tables.py +0 -0
  13. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/actions.py +0 -0
  14. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/config.py +0 -0
  15. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/constants.py +0 -0
  16. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/convert.py +0 -0
  17. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/assign_id.py +0 -0
  18. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/flatten_row.py +0 -0
  19. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/get_nested_field_value.py +0 -0
  20. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/nest_row.py +0 -0
  21. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/search_column_value.py +0 -0
  22. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/set_flat_field_value.py +0 -0
  23. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/functions/set_row_value.py +0 -0
  24. {python_table_processor-0.3.6 → python_table_processor-0.3.7}/table_processor/core/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-table-processor
3
- Version: 0.3.6
3
+ Version: 0.3.7
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.6"
3
+ version = "0.3.7"
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.7"
2
+ __version_tuple__ = (0, 3, 7)
@@ -0,0 +1,41 @@
1
+ '''
2
+ Set the value of a field in a nested dictionary.
3
+ '''
4
+
5
+ from collections import OrderedDict
6
+ from icecream import ic
7
+
8
+ def set_nested_field_value(
9
+ data: OrderedDict | list,
10
+ field: str,
11
+ value: any,
12
+ ):
13
+ if isinstance(field, str) and '.' in field:
14
+ field, rest = field.split('.', 1)
15
+ if isinstance(data, dict):
16
+ sub_data = data.get(field)
17
+ elif isinstance(data, list):
18
+ field = int(field)
19
+ if field < len(data):
20
+ sub_data = data[field]
21
+ else:
22
+ sub_data = None
23
+ if not isinstance(sub_data, dict):
24
+ do_create_dict = True
25
+ if isinstance(sub_data, list):
26
+ # NOTE: 続くフィールド文字列が数字の場合は、リストの要素として扱う
27
+ field2 = rest.split('.', 1)[0]
28
+ if field2.isdigit():
29
+ do_create_dict = False
30
+ if do_create_dict:
31
+ data[field] = OrderedDict()
32
+ set_nested_field_value(data[field], rest, value)
33
+ else:
34
+ try:
35
+ if isinstance(data, dict):
36
+ data[field] = value
37
+ elif isinstance(data, list):
38
+ data[int(field)] = value
39
+ except:
40
+ ic(data, field, value)
41
+ raise
@@ -85,7 +85,7 @@ def merge(
85
85
  if not allow_duplicate_keys:
86
86
  if primary_key in dict_key_to_row:
87
87
  ic(index)
88
- raise ValueError(f'Duplicate key: {key}')
88
+ raise ValueError(f'Duplicate key: {primary_key}')
89
89
  dict_key_to_row[primary_key] = row
90
90
  all_base_rows.append(row)
91
91
  for modification_file in modification_files:
@@ -134,8 +134,6 @@ def merge(
134
134
  #ic(key)
135
135
  #ic(key, value)
136
136
  set_row_value(previous_row, key, value)
137
- #set_row_value(previous_row, '指示追従性?', 'test')
138
- #set_row_value(previous_row, 'modified', True)
139
137
  #ic(previous_row)
140
138
  #ic(previous_row.flat)
141
139
  #raise
@@ -1,2 +0,0 @@
1
- __version__ = "0.3.6"
2
- __version_tuple__ = (0, 3, 6)
@@ -1,24 +0,0 @@
1
- '''
2
- Set the value of a field in a nested dictionary.
3
- '''
4
-
5
- from collections import OrderedDict
6
- from icecream import ic
7
-
8
- def set_nested_field_value(
9
- data: OrderedDict,
10
- field: str,
11
- value: any,
12
- ):
13
- if isinstance(field, str) and '.' in field:
14
- field, rest = field.split('.', 1)
15
- sub_data = data.get(field)
16
- if not isinstance(sub_data, dict):
17
- data[field] = OrderedDict()
18
- set_nested_field_value(data[field], rest, value)
19
- else:
20
- try:
21
- data[field] = value
22
- except:
23
- ic(data, field, value)
24
- raise