python-table-processor 0.3.5__py3-none-any.whl → 0.3.7__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.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,7 +1,7 @@
1
- table_processor/__init__.py,sha256=gtxdmTbOklsCYOkQEth0hoRHsSwKt1ixChUIQPBOStA,52
1
+ table_processor/__init__.py,sha256=voNuwez5LsM9NyDZcQEcA5N7Cg-32xrD7xSIGlYyf6U,52
2
2
  table_processor/cli.py,sha256=uluf_VsBzq3Ldxh3ePGseSrv8--lI7huu-6RjDaHPPg,2170
3
3
  table_processor/commands/convert_tables.py,sha256=w4IZftSlrbt-BMPjldULT_616LSiNE3h7GmrFF7K5OM,2276
4
- table_processor/commands/merge_tables.py,sha256=Uu-hjfPh69Of0_OZrY8sY0oscpLSdK4jwJ_t1qgfPMg,1485
4
+ table_processor/commands/merge_tables.py,sha256=jryGU3gUx2TlGrI6FozGS_aJQvJQFco2LKwun6Uo9KY,1719
5
5
  table_processor/core/actions.py,sha256=GKUKzoPxUEuWSeuY-HsqFoS5Bdm99bjkRhuBgG1s_uk,23658
6
6
  table_processor/core/config.py,sha256=Z1s2r3y4oQXdbDCwIY_hYzoq6VRv7Sb3oUlfBCu13Lc,11646
7
7
  table_processor/core/constants.py,sha256=w-1TxtpXywb6Qh8M4YWuzcCHUvCjy5zJYxaXC3RQS6A,158
@@ -12,12 +12,12 @@ table_processor/core/functions/get_nested_field_value.py,sha256=ZEJi8XtDONoYmhPo
12
12
  table_processor/core/functions/nest_row.py,sha256=b5AKfxE39g-NOLranQRy0dfTZq-27Or8ZlgCB8N5kFs,640
13
13
  table_processor/core/functions/search_column_value.py,sha256=GscwLaMTORHFDhdCdjzdoy46UGyFHrGwDQA2b_tZhsQ,740
14
14
  table_processor/core/functions/set_flat_field_value.py,sha256=7-BgD2yEUGyBaFaIJ18bYv82Qdy0CN8NiC5ZtsAdv44,531
15
- table_processor/core/functions/set_nested_field_value.py,sha256=csO0v_nW94q-M9bNL91xR-TLHPXDDxnLK8gN-0LLd6k,595
15
+ table_processor/core/functions/set_nested_field_value.py,sha256=351AoyL8-dT9I4eBKYlxUME03ACiMjDukebzmhOBaks,1308
16
16
  table_processor/core/functions/set_row_value.py,sha256=wlF_nVGZY74XCzd6pBJJyti62m6y0s1kc5Q6uq9jn8o,641
17
- table_processor/core/merge.py,sha256=NoxVfhpOr7oxfmMZt1Xqx94fkIhAJQcYuYzR3XcJsns,4809
17
+ table_processor/core/merge.py,sha256=5U6fvofaMq6yvllB24M6Pf3uG7Hz17aLKM47NmWHJBc,5027
18
18
  table_processor/core/types.py,sha256=xNvy1vL1ei87kt-MgSfRJSllYrNKRo23pHtJA15DyLQ,2895
19
- python_table_processor-0.3.5.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
- python_table_processor-0.3.5.dist-info/METADATA,sha256=MA1YvRPDWpWhbua0uFd5AOyFJ7EtxUYJ9XV3bYyr2S8,1098
21
- python_table_processor-0.3.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
- python_table_processor-0.3.5.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
- python_table_processor-0.3.5.dist-info/RECORD,,
19
+ python_table_processor-0.3.7.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
+ python_table_processor-0.3.7.dist-info/METADATA,sha256=GTh1Nm6ViWpYlbeO36ncPeJDe35Q8jrClH-xnhEPoRs,1098
21
+ python_table_processor-0.3.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
+ python_table_processor-0.3.7.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
+ python_table_processor-0.3.7.dist-info/RECORD,,
@@ -1,2 +1,2 @@
1
- __version__ = "0.3.5"
2
- __version_tuple__ = (0, 3, 5)
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)
@@ -6,19 +6,36 @@ from collections import OrderedDict
6
6
  from icecream import ic
7
7
 
8
8
  def set_nested_field_value(
9
- data: OrderedDict,
9
+ data: OrderedDict | list,
10
10
  field: str,
11
11
  value: any,
12
12
  ):
13
13
  if isinstance(field, str) and '.' in field:
14
14
  field, rest = field.split('.', 1)
15
- sub_data = data.get(field)
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
16
23
  if not isinstance(sub_data, dict):
17
- data[field] = OrderedDict()
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()
18
32
  set_nested_field_value(data[field], rest, value)
19
33
  else:
20
34
  try:
21
- data[field] = value
35
+ if isinstance(data, dict):
36
+ data[field] = value
37
+ elif isinstance(data, list):
38
+ data[int(field)] = value
22
39
  except:
23
40
  ic(data, field, value)
24
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)