Elron commited on
Commit
0c578b5
1 Parent(s): 40a8c03

Upload dataset.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. dataset.py +19 -8
dataset.py CHANGED
@@ -11,6 +11,7 @@ from .common import __file__ as _
11
  from .dataclass import __file__ as _
12
  from .dict_utils import __file__ as _
13
  from .file_utils import __file__ as _
 
14
  from .fusion import __file__ as _
15
  from .generator_utils import __file__ as _
16
  from .hf_utils import __file__ as _
@@ -27,9 +28,11 @@ from .random_utils import __file__ as _
27
  from .recipe import __file__ as _
28
  from .register import __file__ as _
29
  from .register import register_all_artifacts
 
30
  from .schema import __file__ as _
31
  from .split_utils import __file__ as _
32
  from .splitters import __file__ as _
 
33
  from .stream import __file__ as _
34
  from .task import __file__ as _
35
  from .templates import __file__ as _
@@ -54,14 +57,22 @@ def parse(query: str):
54
  Parses a query of the form 'key1=value1,key2=value2,...' into a dictionary.
55
  """
56
  result = {}
57
- for kv in query.split(","):
58
- parts = kv.split("=")
59
- if parts[1].isdigit():
60
- result[parts[0]] = int(parts[1])
61
- elif parts[1].replace(".", "", 1).isdigit():
62
- result[parts[0]] = float(parts[1])
63
-
64
- result[parts[0]] = parts[1]
 
 
 
 
 
 
 
 
65
 
66
  return result
67
 
 
11
  from .dataclass import __file__ as _
12
  from .dict_utils import __file__ as _
13
  from .file_utils import __file__ as _
14
+ from .formats import __file__ as _
15
  from .fusion import __file__ as _
16
  from .generator_utils import __file__ as _
17
  from .hf_utils import __file__ as _
 
28
  from .recipe import __file__ as _
29
  from .register import __file__ as _
30
  from .register import register_all_artifacts
31
+ from .renderers import __file__ as _
32
  from .schema import __file__ as _
33
  from .split_utils import __file__ as _
34
  from .splitters import __file__ as _
35
+ from .standard import __file__ as _
36
  from .stream import __file__ as _
37
  from .task import __file__ as _
38
  from .templates import __file__ as _
 
57
  Parses a query of the form 'key1=value1,key2=value2,...' into a dictionary.
58
  """
59
  result = {}
60
+ kvs = query.split(",")
61
+ if len(kvs) == 0:
62
+ raise ValueError(
63
+ 'Illegal query: "{query}" should contain at least one assignment of the form: key1=value1,key2=value2'
64
+ )
65
+ for kv in kvs:
66
+ key_val = kv.split("=")
67
+ if len(key_val) != 2 or len(key_val[0].strip()) == 0 or len(key_val[1].strip()) == 0:
68
+ raise ValueError('Illegal query: "{query}" with wrong assignment "{kv}" should be of the form: key=value.')
69
+ key, val = key_val
70
+ if val.isdigit():
71
+ result[key] = int(val)
72
+ elif val.replace(".", "", 1).isdigit():
73
+ result[key] = float(val)
74
+ else:
75
+ result[key] = val
76
 
77
  return result
78