python-table-processor 0.3.8__py3-none-any.whl → 0.3.10__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.
- {python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/METADATA +1 -1
- {python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/RECORD +10 -10
- table_processor/__init__.py +2 -2
- table_processor/commands/merge_tables.py +13 -0
- table_processor/core/actions.py +5 -2
- table_processor/core/merge.py +42 -19
- table_processor/core/types.py +1 -0
- {python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/LICENSE +0 -0
- {python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/WHEEL +0 -0
- {python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/entry_points.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
table_processor/__init__.py,sha256=
|
|
1
|
+
table_processor/__init__.py,sha256=mwLX0OVEDStzXhj4fEvyizEu7Ky92pbEm-V4v6LU4Po,54
|
|
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=
|
|
5
|
-
table_processor/core/actions.py,sha256=
|
|
4
|
+
table_processor/commands/merge_tables.py,sha256=fIk3e-Qbdj3QtOXetC4ItbJs9NfBHVsraRhdfnpy2RQ,2194
|
|
5
|
+
table_processor/core/actions.py,sha256=3yjSW1CKXPn49BNHx0HbjkU5gp8266s5iun57snXqlc,23815
|
|
6
6
|
table_processor/core/config.py,sha256=Z1s2r3y4oQXdbDCwIY_hYzoq6VRv7Sb3oUlfBCu13Lc,11646
|
|
7
7
|
table_processor/core/constants.py,sha256=w-1TxtpXywb6Qh8M4YWuzcCHUvCjy5zJYxaXC3RQS6A,158
|
|
8
8
|
table_processor/core/convert.py,sha256=dzGcpBwJ5omiE8Pw-VmHnGoOqDyh1Rip6BiLdvdf3V8,11561
|
|
@@ -14,10 +14,10 @@ table_processor/core/functions/search_column_value.py,sha256=GscwLaMTORHFDhdCdjz
|
|
|
14
14
|
table_processor/core/functions/set_flat_field_value.py,sha256=7-BgD2yEUGyBaFaIJ18bYv82Qdy0CN8NiC5ZtsAdv44,531
|
|
15
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=
|
|
18
|
-
table_processor/core/types.py,sha256=
|
|
19
|
-
python_table_processor-0.3.
|
|
20
|
-
python_table_processor-0.3.
|
|
21
|
-
python_table_processor-0.3.
|
|
22
|
-
python_table_processor-0.3.
|
|
23
|
-
python_table_processor-0.3.
|
|
17
|
+
table_processor/core/merge.py,sha256=gcMQ5LgBssGBZ0CuSPN0ddslNuLznxwh024kRiGOFLM,5800
|
|
18
|
+
table_processor/core/types.py,sha256=76Fn1PQgO03Swe7E_zFLjusbQ6w9sfxzsL08uHS21hE,2919
|
|
19
|
+
python_table_processor-0.3.10.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
|
|
20
|
+
python_table_processor-0.3.10.dist-info/METADATA,sha256=GUxul_rcnJRWI90S6InJPJkjS5JC9xFzfBXeeRVEkMg,1099
|
|
21
|
+
python_table_processor-0.3.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
22
|
+
python_table_processor-0.3.10.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
|
|
23
|
+
python_table_processor-0.3.10.dist-info/RECORD,,
|
table_processor/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
2
|
-
__version_tuple__ = (0, 3,
|
|
1
|
+
__version__ = "0.3.10"
|
|
2
|
+
__version_tuple__ = (0, 3, 10)
|
|
@@ -17,6 +17,8 @@ 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,
|
|
21
|
+
merge_fields=args.merge_fields,
|
|
20
22
|
)
|
|
21
23
|
|
|
22
24
|
def setup_parser(
|
|
@@ -60,4 +62,15 @@ def setup_parser(
|
|
|
60
62
|
required=False,
|
|
61
63
|
help='Path to output modified data file',
|
|
62
64
|
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
'--output-remaining-data-file', '--output-remaining', '--output-remain',
|
|
67
|
+
required=False,
|
|
68
|
+
help='Path to output remaining data file',
|
|
69
|
+
)
|
|
70
|
+
parser.add_argument(
|
|
71
|
+
'--merge-fields', '--merge-field', '--merge-keys', '--merge-key',
|
|
72
|
+
nargs='+',
|
|
73
|
+
required=False,
|
|
74
|
+
help='Fields to merge',
|
|
75
|
+
)
|
|
63
76
|
parser.set_defaults(handler=run)
|
table_processor/core/actions.py
CHANGED
|
@@ -196,8 +196,10 @@ def setup_actions_with_args(
|
|
|
196
196
|
))
|
|
197
197
|
continue
|
|
198
198
|
if action_name == 'omit':
|
|
199
|
+
purge = options.get('purge', False)
|
|
199
200
|
config.actions.append(OmitConfig(
|
|
200
201
|
field = target,
|
|
202
|
+
purge = purge,
|
|
201
203
|
))
|
|
202
204
|
continue
|
|
203
205
|
if action_name == 'parse':
|
|
@@ -607,8 +609,9 @@ def omit_field(
|
|
|
607
609
|
value, found = pop_row_value(row, config.field)
|
|
608
610
|
if not found:
|
|
609
611
|
return row
|
|
610
|
-
if
|
|
611
|
-
|
|
612
|
+
if not config.purge:
|
|
613
|
+
if f'{STAGING_FIELD}.{config.field}' not in row.flat:
|
|
614
|
+
set_row_staging_value(row, config.field, value)
|
|
612
615
|
return row
|
|
613
616
|
|
|
614
617
|
def join_field(
|
table_processor/core/merge.py
CHANGED
|
@@ -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,17 @@ 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,
|
|
64
|
+
merge_fields: list[str] | None = None,
|
|
50
65
|
):
|
|
51
66
|
ic.enable()
|
|
52
67
|
ic()
|
|
53
68
|
ic(previous_files)
|
|
54
69
|
ic(modification_files)
|
|
55
70
|
ic(keys)
|
|
56
|
-
dict_key_to_row = {}
|
|
71
|
+
#dict_key_to_row = {}
|
|
72
|
+
dict_key_to_row = OrderedDict()
|
|
73
|
+
set_modified_keys = set()
|
|
57
74
|
all_base_rows = []
|
|
58
75
|
all_modified_rows = []
|
|
59
76
|
list_ignored_keys = []
|
|
@@ -74,13 +91,7 @@ def merge(
|
|
|
74
91
|
total=len(df),
|
|
75
92
|
):
|
|
76
93
|
row = prepare_row(flat_row)
|
|
77
|
-
|
|
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)
|
|
94
|
+
primary_key = get_primary_key(row.flat, keys)
|
|
84
95
|
#ic(key)
|
|
85
96
|
if not allow_duplicate_keys:
|
|
86
97
|
if primary_key in dict_key_to_row:
|
|
@@ -104,13 +115,7 @@ def merge(
|
|
|
104
115
|
total=len(df),
|
|
105
116
|
):
|
|
106
117
|
row = prepare_row(flat_row)
|
|
107
|
-
|
|
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)
|
|
118
|
+
primary_key = get_primary_key(row.flat, keys)
|
|
114
119
|
#ic(key)
|
|
115
120
|
#if key not in dict_key_to_row:
|
|
116
121
|
# dict_key_to_row[key] = row
|
|
@@ -128,15 +133,22 @@ def merge(
|
|
|
128
133
|
all_modified_rows.append(previous_row)
|
|
129
134
|
#ic(previous_row)
|
|
130
135
|
#ic(previous_row.flat)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if merge_fields is None:
|
|
137
|
+
merge_fields = []
|
|
138
|
+
for field in row.flat.keys():
|
|
139
|
+
if field.startswith('__staging__.'):
|
|
140
|
+
continue
|
|
141
|
+
merge_fields.append(field)
|
|
142
|
+
for field in merge_fields:
|
|
143
|
+
value, found = search_column_value(row.flat, field)
|
|
134
144
|
#ic(key)
|
|
135
145
|
#ic(key, value)
|
|
136
|
-
|
|
146
|
+
if found:
|
|
147
|
+
set_row_value(previous_row, field, value)
|
|
137
148
|
#ic(previous_row)
|
|
138
149
|
#ic(previous_row.flat)
|
|
139
150
|
#raise
|
|
151
|
+
set_modified_keys.add(primary_key)
|
|
140
152
|
num_modified += 1
|
|
141
153
|
ic(num_modified)
|
|
142
154
|
if ignore_not_found:
|
|
@@ -147,6 +159,17 @@ def merge(
|
|
|
147
159
|
ic('Saving to: ', output_base_data_file)
|
|
148
160
|
save(all_df, output_base_data_file)
|
|
149
161
|
if output_modified_data_file:
|
|
162
|
+
#all_modified_rows = []
|
|
163
|
+
#for key in set_modified_keys:
|
|
164
|
+
# all_modified_rows.append(dict_key_to_row[key])
|
|
150
165
|
all_df = pd.DataFrame([row.flat for row in all_modified_rows])
|
|
151
166
|
ic('Saving to: ', output_modified_data_file)
|
|
152
167
|
save(all_df, output_modified_data_file)
|
|
168
|
+
if output_remaining_data_file:
|
|
169
|
+
remaining_rows = []
|
|
170
|
+
for key, row in dict_key_to_row.items():
|
|
171
|
+
if key not in set_modified_keys:
|
|
172
|
+
remaining_rows.append(row)
|
|
173
|
+
all_df = pd.DataFrame([row.flat for row in remaining_rows])
|
|
174
|
+
ic('Saving to: ', output_remaining_data_file)
|
|
175
|
+
save(all_df, output_remaining_data_file)
|
table_processor/core/types.py
CHANGED
|
File without changes
|
|
File without changes
|
{python_table_processor-0.3.8.dist-info → python_table_processor-0.3.10.dist-info}/entry_points.txt
RENAMED
|
File without changes
|