python-table-processor 0.3.8__tar.gz → 0.3.9__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.8 → python_table_processor-0.3.9}/PKG-INFO +1 -1
  2. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/pyproject.toml +1 -1
  3. python_table_processor-0.3.9/table_processor/__init__.py +2 -0
  4. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/commands/merge_tables.py +6 -0
  5. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/merge.py +28 -15
  6. python_table_processor-0.3.8/table_processor/__init__.py +0 -2
  7. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/LICENSE +0 -0
  8. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/README.md +0 -0
  9. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/cli.py +0 -0
  10. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/commands/convert_tables.py +0 -0
  11. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/actions.py +0 -0
  12. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/config.py +0 -0
  13. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/constants.py +0 -0
  14. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/convert.py +0 -0
  15. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/assign_id.py +0 -0
  16. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/flatten_row.py +0 -0
  17. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/get_nested_field_value.py +0 -0
  18. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/nest_row.py +0 -0
  19. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/search_column_value.py +0 -0
  20. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/set_flat_field_value.py +0 -0
  21. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/set_nested_field_value.py +0 -0
  22. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/table_processor/core/functions/set_row_value.py +0 -0
  23. {python_table_processor-0.3.8 → python_table_processor-0.3.9}/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.8
3
+ Version: 0.3.9
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.8"
3
+ version = "0.3.9"
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.9"
2
+ __version_tuple__ = (0, 3, 9)
@@ -17,6 +17,7 @@ def run(
17
17
  ignore_not_found=args.ignore_not_found,
18
18
  output_base_data_file=args.output_base_data_file,
19
19
  output_modified_data_file=args.output_modified_data_file,
20
+ output_remaining_data_file=args.output_remaining_data_file,
20
21
  )
21
22
 
22
23
  def setup_parser(
@@ -60,4 +61,9 @@ def setup_parser(
60
61
  required=False,
61
62
  help='Path to output modified data file',
62
63
  )
64
+ parser.add_argument(
65
+ '--output-remaining-data-file', '--output-remaining', '--output-remain',
66
+ required=False,
67
+ help='Path to output remaining data file',
68
+ )
63
69
  parser.set_defaults(handler=run)
@@ -39,6 +39,19 @@ from . convert import (
39
39
  save,
40
40
  )
41
41
 
42
+ def get_primary_key(
43
+ row: Mapping,
44
+ keys: list[str],
45
+ ):
46
+ list_keys = []
47
+ for key in keys:
48
+ value, found = search_column_value(row, key)
49
+ if not found:
50
+ raise KeyError(f'Column not found: {key}, existing columns: {row.keys()}')
51
+ list_keys.append(value)
52
+ primary_key = tuple(list_keys)
53
+ return primary_key
54
+
42
55
  def merge(
43
56
  previous_files: list[str],
44
57
  modification_files: list[str],
@@ -47,13 +60,16 @@ def merge(
47
60
  ignore_not_found: bool = False,
48
61
  output_base_data_file: str | None = None,
49
62
  output_modified_data_file: str | None = None,
63
+ output_remaining_data_file: str | None = None,
50
64
  ):
51
65
  ic.enable()
52
66
  ic()
53
67
  ic(previous_files)
54
68
  ic(modification_files)
55
69
  ic(keys)
56
- dict_key_to_row = {}
70
+ #dict_key_to_row = {}
71
+ dict_key_to_row = OrderedDict()
72
+ set_modified_keys = set()
57
73
  all_base_rows = []
58
74
  all_modified_rows = []
59
75
  list_ignored_keys = []
@@ -74,13 +90,7 @@ def merge(
74
90
  total=len(df),
75
91
  ):
76
92
  row = prepare_row(flat_row)
77
- list_keys = []
78
- for key in keys:
79
- value, found = search_column_value(row.nested, key)
80
- if not found:
81
- raise KeyError(f'Column not found: {key}, existing columns: {row.flat.keys()}')
82
- list_keys.append(value)
83
- primary_key = tuple(list_keys)
93
+ primary_key = get_primary_key(row.flat, keys)
84
94
  #ic(key)
85
95
  if not allow_duplicate_keys:
86
96
  if primary_key in dict_key_to_row:
@@ -104,13 +114,7 @@ def merge(
104
114
  total=len(df),
105
115
  ):
106
116
  row = prepare_row(flat_row)
107
- list_keys = []
108
- for key in keys:
109
- value, found = search_column_value(row.nested, key)
110
- if not found:
111
- raise KeyError(f'Column not found: {key}, existing columns: {row.flat.keys()}')
112
- list_keys.append(value)
113
- primary_key = tuple(list_keys)
117
+ primary_key = get_primary_key(row.flat, keys)
114
118
  #ic(key)
115
119
  #if key not in dict_key_to_row:
116
120
  # dict_key_to_row[key] = row
@@ -137,6 +141,7 @@ def merge(
137
141
  #ic(previous_row)
138
142
  #ic(previous_row.flat)
139
143
  #raise
144
+ set_modified_keys.add(primary_key)
140
145
  num_modified += 1
141
146
  ic(num_modified)
142
147
  if ignore_not_found:
@@ -150,3 +155,11 @@ def merge(
150
155
  all_df = pd.DataFrame([row.flat for row in all_modified_rows])
151
156
  ic('Saving to: ', output_modified_data_file)
152
157
  save(all_df, output_modified_data_file)
158
+ if output_remaining_data_file:
159
+ remaining_rows = []
160
+ for key, row in dict_key_to_row.items():
161
+ if key not in set_modified_keys:
162
+ remaining_rows.append(row)
163
+ all_df = pd.DataFrame([row.flat for row in remaining_rows])
164
+ ic('Saving to: ', output_remaining_data_file)
165
+ save(all_df, output_remaining_data_file)
@@ -1,2 +0,0 @@
1
- __version__ = "0.3.8"
2
- __version_tuple__ = (0, 3, 8)