python-table-converter 0.2.14__tar.gz → 0.2.17__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.
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/PKG-INFO +1 -1
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/pyproject.toml +1 -1
- python_table_converter-0.2.17/table_converter/__init__.py +2 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/commands/convert_tables.py +7 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/actions.py +15 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/convert.py +22 -1
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/types.py +1 -1
- python_table_converter-0.2.14/table_converter/__init__.py +0 -2
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/LICENSE +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/README.md +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/cli.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/config.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/constants.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/assign_id.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/flatten_row.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/get_nested_field_value.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/nest_row.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/search_column_value.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/set_flat_field_value.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/set_nested_field_value.py +0 -0
- {python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/functions/set_row_value.py +0 -0
|
@@ -12,6 +12,7 @@ def run(
|
|
|
12
12
|
convert(
|
|
13
13
|
input_files = args.input_files,
|
|
14
14
|
output_file = args.output_file,
|
|
15
|
+
output_file_filtered_out = args.output_file_filtered_out,
|
|
15
16
|
config_path = args.config,
|
|
16
17
|
list_actions = args.do_actions,
|
|
17
18
|
list_pick_columns = args.pick_columns,
|
|
@@ -34,6 +35,12 @@ def setup_parser(
|
|
|
34
35
|
required=True,
|
|
35
36
|
help='Path to the output file.'
|
|
36
37
|
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
'--output-file-filtered-out', '--output-filtered-out', '-f',
|
|
40
|
+
metavar='OUTPUT_FILE_FILTERED_OUT',
|
|
41
|
+
required=False,
|
|
42
|
+
help='Path to the output file for filtered out rows.',
|
|
43
|
+
)
|
|
37
44
|
parser.add_argument(
|
|
38
45
|
'--config', '-c',
|
|
39
46
|
type=str,
|
{python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/actions.py
RENAMED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Actions are used to transform the data in the table.
|
|
3
3
|
'''
|
|
4
4
|
|
|
5
|
+
import re
|
|
6
|
+
|
|
5
7
|
from collections import OrderedDict
|
|
6
8
|
from dataclasses import dataclass
|
|
7
9
|
from typing import (
|
|
@@ -190,6 +192,14 @@ def setup_filter_action(
|
|
|
190
192
|
value = value.strip(),
|
|
191
193
|
))
|
|
192
194
|
return config
|
|
195
|
+
if '=~' in str_filter:
|
|
196
|
+
field, value = str_filter.split('=~')
|
|
197
|
+
config.actions.append(FilterConfig(
|
|
198
|
+
field = field.strip(),
|
|
199
|
+
operator = '=~',
|
|
200
|
+
value = value.strip(),
|
|
201
|
+
))
|
|
202
|
+
return config
|
|
193
203
|
raise ValueError(
|
|
194
204
|
f'Unsupported filter: {str_filter}'
|
|
195
205
|
)
|
|
@@ -383,6 +393,11 @@ def filter_row(
|
|
|
383
393
|
elif config.operator == '!=':
|
|
384
394
|
if str(value) == str(config.value) or value == config.value:
|
|
385
395
|
return False
|
|
396
|
+
elif config.operator == '=~':
|
|
397
|
+
if not found:
|
|
398
|
+
return False
|
|
399
|
+
if not re.search(config.value, value):
|
|
400
|
+
return False
|
|
386
401
|
elif config.operator == 'not-in':
|
|
387
402
|
if isinstance(config.value, list):
|
|
388
403
|
if value in config.value:
|
{python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/convert.py
RENAMED
|
@@ -119,6 +119,18 @@ def save_json(
|
|
|
119
119
|
ensure_ascii=False,
|
|
120
120
|
)
|
|
121
121
|
|
|
122
|
+
@register_loader('.jsonl')
|
|
123
|
+
def load_jsonl(
|
|
124
|
+
input_file: str,
|
|
125
|
+
):
|
|
126
|
+
rows = []
|
|
127
|
+
with open(input_file, 'r') as f:
|
|
128
|
+
for line in f:
|
|
129
|
+
row = json.loads(line)
|
|
130
|
+
rows.append(row)
|
|
131
|
+
df = pd.DataFrame(rows)
|
|
132
|
+
return df
|
|
133
|
+
|
|
122
134
|
@register_saver('.jsonl')
|
|
123
135
|
def save_jsonl(
|
|
124
136
|
df: pd.DataFrame,
|
|
@@ -244,6 +256,7 @@ def assign_length(
|
|
|
244
256
|
def convert(
|
|
245
257
|
input_files: list[str],
|
|
246
258
|
output_file: str | None = None,
|
|
259
|
+
output_file_filtered_out: str | None = None,
|
|
247
260
|
config_path: str | None = None,
|
|
248
261
|
output_debug: bool = False,
|
|
249
262
|
list_actions: list[str] | None = None,
|
|
@@ -254,6 +267,7 @@ def convert(
|
|
|
254
267
|
ic()
|
|
255
268
|
ic(input_files)
|
|
256
269
|
df_list = []
|
|
270
|
+
row_list_filtered_out = []
|
|
257
271
|
global_status = GlobalStatus()
|
|
258
272
|
config = setup_config(config_path)
|
|
259
273
|
ic(config)
|
|
@@ -300,9 +314,12 @@ def convert(
|
|
|
300
314
|
if config.actions:
|
|
301
315
|
new_row = do_actions(global_status, row, config.actions)
|
|
302
316
|
if new_row is None:
|
|
303
|
-
if
|
|
317
|
+
if not output_debug:
|
|
304
318
|
pop_row_staging(row)
|
|
319
|
+
if verbose:
|
|
305
320
|
ic('Filtered out: ', row.flat)
|
|
321
|
+
if output_file_filtered_out:
|
|
322
|
+
row_list_filtered_out.append(row.flat)
|
|
306
323
|
continue
|
|
307
324
|
row = new_row
|
|
308
325
|
if config.pick:
|
|
@@ -320,3 +337,7 @@ def convert(
|
|
|
320
337
|
if output_file:
|
|
321
338
|
ic('Saing to: ', output_file)
|
|
322
339
|
saver(all_df, output_file)
|
|
340
|
+
if row_list_filtered_out:
|
|
341
|
+
df_filtered_out = pd.DataFrame(row_list_filtered_out)
|
|
342
|
+
ic('Saving filtered out to: ', output_file_filtered_out)
|
|
343
|
+
saver(df_filtered_out, output_file_filtered_out)
|
{python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/types.py
RENAMED
|
@@ -40,7 +40,7 @@ class AssignIdConfig:
|
|
|
40
40
|
@dataclasses.dataclass
|
|
41
41
|
class FilterConfig:
|
|
42
42
|
field: str
|
|
43
|
-
operator: Literal['==', '!=', '>', '>=', '<', '<=', 'not-in']
|
|
43
|
+
operator: Literal['==', '!=', '>', '>=', '<', '<=', '=~', 'not-in']
|
|
44
44
|
value: str | list[str]
|
|
45
45
|
|
|
46
46
|
@dataclasses.dataclass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/config.py
RENAMED
|
File without changes
|
{python_table_converter-0.2.14 → python_table_converter-0.2.17}/table_converter/core/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|