python-table-processor 0.3.2__py3-none-any.whl → 0.3.3__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.2
3
+ Version: 0.3.3
4
4
  Summary: A table data processor
5
5
  Home-page: https://github.com/akivajp/python-table-processor
6
6
  License: MIT
@@ -1,8 +1,8 @@
1
- table_processor/__init__.py,sha256=TQqqDugVb2WjmgqPXyxUA42oi3QOxyPDqpr09kjKGlk,52
1
+ table_processor/__init__.py,sha256=IqYTIOR96kwEp7nfLi1h2e7pZiFKmLonFJ-wwSegFkw,52
2
2
  table_processor/cli.py,sha256=uluf_VsBzq3Ldxh3ePGseSrv8--lI7huu-6RjDaHPPg,2170
3
3
  table_processor/commands/convert_tables.py,sha256=j25KL0zRl5ikrBk73jAkKn4rPmDq7SecChZxecDpILQ,2123
4
4
  table_processor/commands/merge_tables.py,sha256=Uu-hjfPh69Of0_OZrY8sY0oscpLSdK4jwJ_t1qgfPMg,1485
5
- table_processor/core/actions.py,sha256=iCBm-tj_gTxeHxPaBSILdYAe8-75XaDtsCOTJp1jGfA,20264
5
+ table_processor/core/actions.py,sha256=WLlq-G8Pb9xjsLpXK1QVCwhK20ijz2oIbTFibihdFTE,21557
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=cibzqJ5hHsfX_7qUz4kE2Gi-WH4UMqecBl3kSb4IVsY,11140
@@ -15,9 +15,9 @@ table_processor/core/functions/set_flat_field_value.py,sha256=7-BgD2yEUGyBaFaIJ1
15
15
  table_processor/core/functions/set_nested_field_value.py,sha256=csO0v_nW94q-M9bNL91xR-TLHPXDDxnLK8gN-0LLd6k,595
16
16
  table_processor/core/functions/set_row_value.py,sha256=wlF_nVGZY74XCzd6pBJJyti62m6y0s1kc5Q6uq9jn8o,641
17
17
  table_processor/core/merge.py,sha256=Yc5OV9n1xV9QtgY4srl6Susd5cOKbuYseEtYuBampDw,4672
18
- table_processor/core/types.py,sha256=rxmiWsUCEBkjveO84tbMJ1kVn_P13Ywl89wDHMWEej0,2580
19
- python_table_processor-0.3.2.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
- python_table_processor-0.3.2.dist-info/METADATA,sha256=PCCGEqAansu5aIrmLu4eaFl3HhD2DCbDuDt2ru0-nRs,1098
21
- python_table_processor-0.3.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
- python_table_processor-0.3.2.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
- python_table_processor-0.3.2.dist-info/RECORD,,
18
+ table_processor/core/types.py,sha256=qASw6zDJXFpaswKjhSQ39wcTH8BcCmp7xKW_hgP-RRY,2665
19
+ python_table_processor-0.3.3.dist-info/LICENSE,sha256=1_Gn0I1neLPxDLfLiHEyxjDg-pbAra1p2iHEqutGS_c,1068
20
+ python_table_processor-0.3.3.dist-info/METADATA,sha256=mvhOnT4vISkKBt5HCEecLCTIRrwrWivJyn63II1w5Jk,1098
21
+ python_table_processor-0.3.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
+ python_table_processor-0.3.3.dist-info/entry_points.txt,sha256=lq97F6m51yZ93qmVIqkUHJfbILZuYLxrMWXSqrP4JpM,118
23
+ python_table_processor-0.3.3.dist-info/RECORD,,
@@ -1,2 +1,2 @@
1
- __version__ = "0.3.2"
2
- __version_tuple__ = (0, 3, 2)
1
+ __version__ = "0.3.3"
2
+ __version_tuple__ = (0, 3, 3)
@@ -177,15 +177,26 @@ def setup_actions_with_args(
177
177
  if action_name == 'parse':
178
178
  as_type = options.get('as', 'literal')
179
179
  required = options.get('required', False)
180
- if as_type not in ['json', 'literal']:
180
+ if as_type in ['boolean']:
181
+ as_type = 'bool'
182
+ if as_type not in ['bool', 'json', 'literal']:
181
183
  raise ValueError(
182
184
  f'Unsupported as type: {as_type}'
183
185
  )
186
+ assign_default = False
187
+ default_value = None
188
+ if 'default' in options:
189
+ assign_default = True
190
+ default_value = options['default']
191
+ if default_value in ['None', 'none', 'Null', 'null']:
192
+ default_value = None
184
193
  config.actions.append(ParseConfig(
185
194
  target = target,
186
195
  source = source,
187
196
  as_type = as_type,
188
197
  required = required,
198
+ assign_default = assign_default,
199
+ default_value = default_value,
189
200
  ))
190
201
  continue
191
202
  if action_name == 'parse-json':
@@ -599,27 +610,48 @@ def parse(
599
610
  f'Required field not found, field: {config.source}'
600
611
  )
601
612
  if found:
602
- if type(value) == str:
603
- if config.as_type == 'literal':
604
- try:
613
+ if config.as_type == 'literal':
614
+ try:
615
+ if type(value) is str:
605
616
  parsed = ast.literal_eval(value)
606
- except:
607
- raise ValueError(
608
- f'Failed to parse literal: {value}'
609
- )
610
- elif config.as_type == 'json':
611
- try:
617
+ else:
618
+ parsed = value
619
+ except:
620
+ raise ValueError(
621
+ f'Failed to parse literal: {value}'
622
+ )
623
+ elif config.as_type == 'json':
624
+ try:
625
+ if type(value) is str:
612
626
  parsed = json.loads(value)
613
- except:
627
+ else:
628
+ parsed = value
629
+ except:
630
+ raise ValueError(
631
+ f'Failed to parse JSON: {value}'
632
+ )
633
+ elif config.as_type == 'bool':
634
+ if config.assign_default and value in [None, '']:
635
+ value = config.default_value
636
+ if type(value) is bool:
637
+ parsed = value
638
+ elif type(value) is str:
639
+ if value.lower() in ['true', 'yes', 'on', '1']:
640
+ parsed = True
641
+ elif value.lower() in ['false', 'no', 'off', '0']:
642
+ parsed = False
643
+ else:
614
644
  raise ValueError(
615
- f'Failed to parse JSON: {value}'
645
+ f'Failed to parse bool: {value}'
616
646
  )
617
647
  else:
618
648
  raise ValueError(
619
- f'Unsupported as type: {config.as_type}'
649
+ f'Failed to parse bool: {value}'
620
650
  )
621
651
  else:
622
- parsed = value
652
+ raise ValueError(
653
+ f'Unsupported as type: {config.as_type}'
654
+ )
623
655
  set_row_staging_value(row, config.target, parsed)
624
656
  return row
625
657
 
@@ -74,8 +74,12 @@ class OmitConfig:
74
74
  class ParseConfig:
75
75
  target: str
76
76
  source: str
77
- as_type: Literal['json', 'literal']
77
+ as_type: Literal[
78
+ 'bool', 'json', 'literal'
79
+ ]
78
80
  required: bool = False
81
+ assign_default: bool = False
82
+ default_value: Any = None
79
83
 
80
84
  @dataclasses.dataclass
81
85
  class PickConfig: