python-table-converter 0.2.10__tar.gz → 0.2.11__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 (16) hide show
  1. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/PKG-INFO +1 -1
  2. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/pyproject.toml +1 -1
  3. python_table_converter-0.2.11/table_converter/__init__.py +2 -0
  4. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/config.py +44 -3
  5. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/convert.py +18 -10
  6. python_table_converter-0.2.10/table_converter/__init__.py +0 -2
  7. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/LICENSE +0 -0
  8. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/README.md +0 -0
  9. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/cli.py +0 -0
  10. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/commands/convert_tables.py +0 -0
  11. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/constants.py +0 -0
  12. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/functions/assign_id.py +0 -0
  13. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/functions/flatten.py +0 -0
  14. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/functions/get_field_value.py +0 -0
  15. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/functions/search_column_value.py +0 -0
  16. {python_table_converter-0.2.10 → python_table_converter-0.2.11}/table_converter/core/functions/set_field_value.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-table-converter
3
- Version: 0.2.10
3
+ Version: 0.2.11
4
4
  Summary: A table data converter
5
5
  Home-page: https://github.com/akivajp/python-table-converter
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-table-converter"
3
- version = "0.2.10"
3
+ version = "0.2.11"
4
4
  description = "A table data converter"
5
5
  authors = ["Akiva Miura <akiva.miura@gmail.com>"]
6
6
  license = "MIT"
@@ -0,0 +1,2 @@
1
+ __version__ = "0.2.11"
2
+ __version_tuple__ = (0, 2, 11)
@@ -27,6 +27,11 @@ class FilterConfig:
27
27
  operator: Literal['==', '!=', '>', '>=', '<', '<=']
28
28
  value: str
29
29
 
30
+ @dataclasses.dataclass
31
+ class SplitConfig:
32
+ field: str
33
+ delimiter: str
34
+
30
35
  @dataclasses.dataclass
31
36
  class ProcessConfig:
32
37
  assign_constants: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
@@ -35,7 +40,8 @@ class ProcessConfig:
35
40
  #filter_eq: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
36
41
  filter: list[FilterConfig] = dataclasses.field(default_factory=list)
37
42
  omit_fields: list[str] = dataclasses.field(default_factory=list)
38
- split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
43
+ #split_by_newline: FlatFieldMap = dataclasses.field(default_factory=OrderedDict)
44
+ split: Mapping[str, SplitConfig] = dataclasses.field(default_factory=OrderedDict)
39
45
 
40
46
  def __setitem__(self, key, value):
41
47
  setattr(self, key, value)
@@ -76,13 +82,12 @@ def setup_process_config(
76
82
  for process_key in [
77
83
  'assign_constants',
78
84
  'assign_formats',
79
- 'filter_eq',
80
- 'split_by_newline',
81
85
  ]:
82
86
  dict_subprocess = dict_process.get(process_key)
83
87
  if isinstance(dict_subprocess, Mapping):
84
88
  config.process[process_key] = flatten(loaded['process'][process_key])
85
89
  setup_process_assign_ids_config(config, dict_process)
90
+ setup_process_split_config(config, dict_process)
86
91
 
87
92
  def setup_process_assign_ids_config(
88
93
  config: Config,
@@ -120,3 +125,39 @@ def setup_process_assign_ids_config(
120
125
  raise ValueError(
121
126
  f'Unsupported assign_ids value type: {type(value)}'
122
127
  )
128
+
129
+ def setup_process_split_config(
130
+ config: Config,
131
+ dict_process: Mapping,
132
+ ):
133
+ dict_subprocess = dict_process.get('split')
134
+ if isinstance(dict_subprocess, Mapping):
135
+ for key, value in dict_subprocess.items():
136
+ if isinstance(value, Mapping):
137
+ field = value.get('field')
138
+ if not field:
139
+ ic.enable()
140
+ ic(value)
141
+ ic(value.get('field'))
142
+ raise ValueError(
143
+ 'Field is required for split.'
144
+ )
145
+ delimiter = value.get('delimiter')
146
+ if not delimiter:
147
+ ic.enable()
148
+ ic(value)
149
+ ic(value.get('delimiter'))
150
+ raise ValueError(
151
+ 'Delimiter is required for split.'
152
+ )
153
+ config.process.split[key] = SplitConfig(
154
+ field = field,
155
+ delimiter = delimiter,
156
+ )
157
+ else:
158
+ ic.enable()
159
+ ic(value)
160
+ ic(type(value))
161
+ raise ValueError(
162
+ f'Unsupported assign_ids value type: {type(value)}'
163
+ )
@@ -16,6 +16,7 @@ import pandas as pd
16
16
 
17
17
  from . config import (
18
18
  FilterConfig,
19
+ SplitConfig,
19
20
  setup_config,
20
21
  )
21
22
  from . constants import (
@@ -193,19 +194,22 @@ def remap_columns(
193
194
  new_row[column] = row[column]
194
195
  return new_row
195
196
 
196
- def apply_fields_split_by_newline(
197
+ def split_fields(
197
198
  row: OrderedDict,
198
- dict_fields: OrderedDict,
199
+ dict_config: list[SplitConfig],
199
200
  ):
200
201
  new_row = OrderedDict(row)
201
- for column in dict_fields:
202
- value, found = search_column_value(row, dict_fields[column])
202
+ for dst, config in dict_config.items():
203
+ value, found = search_column_value(row, config.field)
203
204
  if found:
204
205
  if isinstance(value, str):
205
- new_value = value.split('\n')
206
- new_row[f'{STAGING_FIELD}.{column}'] = new_value
206
+ new_value = value.split(config.delimiter)
207
+ new_value = list(filter(None, new_value))
208
+ if not new_value:
209
+ ic(dst, config, value)
210
+ new_row[f'{STAGING_FIELD}.{dst}'] = new_value
207
211
  else:
208
- new_row[f'{STAGING_FIELD}.{column}'] = value
212
+ new_row[f'{STAGING_FIELD}.{dst}'] = value
209
213
  return new_row
210
214
 
211
215
  def filter_row(
@@ -275,7 +279,11 @@ def convert(
275
279
  for field in fields:
276
280
  if '=' in field:
277
281
  dst, src = field.split('=')
278
- config.process.split_by_newline[dst] = src
282
+ #config.process.split_by_newline[dst] = src
283
+ config.process.split[dst] = SplitConfig(
284
+ field = src,
285
+ delimiter = '\n',
286
+ )
279
287
  else:
280
288
  raise ValueError(f'Invalid split by newline: {field}')
281
289
  if str_filters:
@@ -339,8 +347,8 @@ def convert(
339
347
  new_flat_row = map_constants(new_flat_row, config.process.assign_constants)
340
348
  if config.map:
341
349
  new_flat_row = remap_columns(new_flat_row, config.map)
342
- if config.process.split_by_newline:
343
- new_flat_row = apply_fields_split_by_newline(new_flat_row, config.process.split_by_newline)
350
+ if config.process.split:
351
+ new_flat_row = split_fields(new_flat_row, config.process.split)
344
352
  if config.process.assign_ids:
345
353
  new_flat_row = assign_id(new_flat_row, config.process.assign_ids, id_context_map)
346
354
  if config.process.assign_formats:
@@ -1,2 +0,0 @@
1
- __version__ = "0.2.10"
2
- __version_tuple__ = (0, 2, 10)