python-table-converter 0.2.6__tar.gz → 0.2.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-table-converter
3
- Version: 0.2.6
3
+ Version: 0.2.8
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.6"
3
+ version = "0.2.8"
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.8"
2
+ __version_tuple__ = (0, 2, 8)
@@ -39,8 +39,17 @@ def command_convert_tables(
39
39
  if parser is None:
40
40
  parse_and_run(command_parser)
41
41
 
42
+ def setup_common_args(
43
+ parser: argparse.ArgumentParser,
44
+ ):
45
+ parser.add_argument(
46
+ '--verbose', '-v',
47
+ action='store_true',
48
+ )
49
+
42
50
  def main():
43
51
  parser = argparse.ArgumentParser(description='Table Data Converter')
52
+ setup_common_args(parser)
44
53
  parser.set_defaults(handler=None)
45
54
  subparsers = parser.add_subparsers(dest='command')
46
55
 
@@ -48,6 +57,7 @@ def main():
48
57
  'convert',
49
58
  help='Convert a table to a different format.'
50
59
  )
60
+ setup_common_args(parser_convert_tables)
51
61
  command_convert_tables(parser_convert_tables)
52
62
 
53
63
  parse_and_run(parser)
@@ -24,10 +24,6 @@ def run(
24
24
  def setup_parser(
25
25
  parser: argparse.ArgumentParser,
26
26
  ):
27
- parser.add_argument(
28
- '--verbose', '-v',
29
- action='store_true',
30
- )
31
27
  parser.add_argument(
32
28
  'input_files',
33
29
  metavar='INPUT_FILE',
@@ -52,6 +52,15 @@ def load_excel(
52
52
  df = pd.read_excel(input_file)
53
53
  return df
54
54
 
55
+ @register_loader('.json')
56
+ def load_json(
57
+ input_file: str,
58
+ ):
59
+ with open(input_file, 'r') as f:
60
+ data = json.load(f)
61
+ df = pd.DataFrame(data)
62
+ return df
63
+
55
64
  @register_saver('.json')
56
65
  def save_json(
57
66
  df: pd.DataFrame,
@@ -261,8 +270,9 @@ def convert(
261
270
  for index, row in df.iterrows():
262
271
  orig = OrderedDict(row)
263
272
  new_row = OrderedDict(row)
264
- set_field_value(new_row, f'{STAGING_FIELD}.{INPUT_FIELD}', orig)
265
- set_field_value(new_row, f'{STAGING_FIELD}.{FILE_FIELD}', input_file)
273
+ if STAGING_FIELD not in new_row:
274
+ set_field_value(new_row, f'{STAGING_FIELD}.{INPUT_FIELD}', orig)
275
+ set_field_value(new_row, f'{STAGING_FIELD}.{FILE_FIELD}', input_file)
266
276
  if config.process.assign_constants:
267
277
  new_row = map_constants(new_row, config.process.assign_constants)
268
278
  if config.map:
@@ -1,2 +0,0 @@
1
- __version__ = "0.2.6"
2
- __version_tuple__ = (0, 2, 6)