python-table-processor 0.3.5__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.5 → python_table_processor-0.3.7}/PKG-INFO +1 -1
  2. {python_table_processor-0.3.5 → 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.5 → python_table_processor-0.3.7}/table_processor/commands/merge_tables.py +9 -4
  5. python_table_processor-0.3.7/table_processor/core/functions/set_nested_field_value.py +41 -0
  6. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/merge.py +15 -11
  7. python_table_processor-0.3.5/table_processor/__init__.py +0 -2
  8. python_table_processor-0.3.5/table_processor/core/functions/set_nested_field_value.py +0 -24
  9. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/LICENSE +0 -0
  10. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/README.md +0 -0
  11. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/cli.py +0 -0
  12. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/commands/convert_tables.py +0 -0
  13. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/actions.py +0 -0
  14. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/config.py +0 -0
  15. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/constants.py +0 -0
  16. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/convert.py +0 -0
  17. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/assign_id.py +0 -0
  18. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/flatten_row.py +0 -0
  19. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/get_nested_field_value.py +0 -0
  20. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/nest_row.py +0 -0
  21. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/search_column_value.py +0 -0
  22. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/set_flat_field_value.py +0 -0
  23. {python_table_processor-0.3.5 → python_table_processor-0.3.7}/table_processor/core/functions/set_row_value.py +0 -0
  24. {python_table_processor-0.3.5 → 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.5
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.5"
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)
@@ -15,7 +15,8 @@ def run(
15
15
  keys=args.keys,
16
16
  allow_duplicate_keys=args.allow_duplicate_keys,
17
17
  ignore_not_found=args.ignore_not_found,
18
- output_file=args.output_file,
18
+ output_base_data_file=args.output_base_data_file,
19
+ output_modified_data_file=args.output_modified_data_file,
19
20
  )
20
21
 
21
22
  def setup_parser(
@@ -50,9 +51,13 @@ def setup_parser(
50
51
  help='Ignore not found',
51
52
  )
52
53
  parser.add_argument(
53
- '--output-file', '--output', '-o',
54
- metavar='OUTPUT_FILE',
54
+ '--output-base-data-file', '--output-base',
55
55
  required=False,
56
- help='Path to the output file.',
56
+ help='Path to output base data file',
57
+ )
58
+ parser.add_argument(
59
+ '--output-modified-data-file', '--output-modified',
60
+ required=False,
61
+ help='Path to output modified data file',
57
62
  )
58
63
  parser.set_defaults(handler=run)
@@ -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
@@ -45,7 +45,8 @@ def merge(
45
45
  keys: list[str],
46
46
  allow_duplicate_keys: bool = False,
47
47
  ignore_not_found: bool = False,
48
- output_file: str | None = None,
48
+ output_base_data_file: str | None = None,
49
+ output_modified_data_file: str | None = None,
49
50
  ):
50
51
  ic.enable()
51
52
  ic()
@@ -53,7 +54,8 @@ def merge(
53
54
  ic(modification_files)
54
55
  ic(keys)
55
56
  dict_key_to_row = {}
56
- all_rows = []
57
+ all_base_rows = []
58
+ all_modified_rows = []
57
59
  list_ignored_keys = []
58
60
  num_modified = 0
59
61
  for previous_file in previous_files:
@@ -83,9 +85,9 @@ def merge(
83
85
  if not allow_duplicate_keys:
84
86
  if primary_key in dict_key_to_row:
85
87
  ic(index)
86
- raise ValueError(f'Duplicate key: {key}')
88
+ raise ValueError(f'Duplicate key: {primary_key}')
87
89
  dict_key_to_row[primary_key] = row
88
- all_rows.append(row)
90
+ all_base_rows.append(row)
89
91
  for modification_file in modification_files:
90
92
  if not os.path.exists(modification_file):
91
93
  raise FileNotFoundError(f'File not found: {modification_file}')
@@ -123,6 +125,7 @@ def merge(
123
125
  ic(index)
124
126
  raise ValueError(f'Key not found: {primary_key}')
125
127
  previous_row = dict_key_to_row[primary_key]
128
+ all_modified_rows.append(previous_row)
126
129
  #ic(previous_row)
127
130
  #ic(previous_row.flat)
128
131
  for key, value in row.flat.items():
@@ -131,8 +134,6 @@ def merge(
131
134
  #ic(key)
132
135
  #ic(key, value)
133
136
  set_row_value(previous_row, key, value)
134
- #set_row_value(previous_row, '指示追従性?', 'test')
135
- #set_row_value(previous_row, 'modified', True)
136
137
  #ic(previous_row)
137
138
  #ic(previous_row.flat)
138
139
  #raise
@@ -141,8 +142,11 @@ def merge(
141
142
  if ignore_not_found:
142
143
  ic(len(list_ignored_keys))
143
144
  ic(list_ignored_keys)
144
- if output_file:
145
- #all_df = pd.DataFrame(all_rows)
146
- all_df = pd.DataFrame([row.flat for row in all_rows])
147
- ic('Saving to: ', output_file)
148
- save(all_df, output_file)
145
+ if output_base_data_file:
146
+ all_df = pd.DataFrame([row.flat for row in all_base_rows])
147
+ ic('Saving to: ', output_base_data_file)
148
+ save(all_df, output_base_data_file)
149
+ if output_modified_data_file:
150
+ all_df = pd.DataFrame([row.flat for row in all_modified_rows])
151
+ ic('Saving to: ', output_modified_data_file)
152
+ save(all_df, output_modified_data_file)
@@ -1,2 +0,0 @@
1
- __version__ = "0.3.5"
2
- __version_tuple__ = (0, 3, 5)
@@ -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