Upload normalizers.py with huggingface_hub
Browse files- normalizers.py +7 -3
normalizers.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from typing import Any, Dict, List
|
| 2 |
|
| 3 |
from .operator import StreamInstanceOperator
|
| 4 |
|
|
@@ -9,10 +9,14 @@ class NormalizeListFields(StreamInstanceOperator):
|
|
| 9 |
empty_value: str = ""
|
| 10 |
separator: str = ", "
|
| 11 |
|
| 12 |
-
def process(
|
|
|
|
|
|
|
| 13 |
for field in self.fields:
|
| 14 |
assert field in instance, f"Field {field} not found in instance {instance}"
|
| 15 |
-
assert isinstance(
|
|
|
|
|
|
|
| 16 |
|
| 17 |
target_key = self.key_prefix + field
|
| 18 |
|
|
|
|
| 1 |
+
from typing import Any, Dict, List, Optional
|
| 2 |
|
| 3 |
from .operator import StreamInstanceOperator
|
| 4 |
|
|
|
|
| 9 |
empty_value: str = ""
|
| 10 |
separator: str = ", "
|
| 11 |
|
| 12 |
+
def process(
|
| 13 |
+
self, instance: Dict[str, Any], stream_name: Optional[str] = None
|
| 14 |
+
) -> Dict[str, Any]:
|
| 15 |
for field in self.fields:
|
| 16 |
assert field in instance, f"Field {field} not found in instance {instance}"
|
| 17 |
+
assert isinstance(
|
| 18 |
+
instance[field], list
|
| 19 |
+
), f"Field {field} should be a list, got {type(instance[field])}"
|
| 20 |
|
| 21 |
target_key = self.key_prefix + field
|
| 22 |
|