Upload operators.py with huggingface_hub
Browse files143 unmodified lines14414514614714814915015125 unmodified lines177178179178180181182183184185186187188189298 unmodified lines4884894904834914924934943 unmodified lines49849950049350150250350410 unmodified lines515516517510518519520521522523524525526143 unmodified lines field_to_field: Optional[Union[List[Tuple[str, str]], Dict[str, str]]] = None process_every_value: bool = False use_query: bool = False get_default: Any = None not_exist_ok: bool = False
def verify(self): super().verify()25 unmodified lines def process(self, instance: Dict[str, Any], stream_name: str = None) -> Dict[str, Any]: for from_field, to_field in self._field_to_field: try: old_value = dict_get(instance, from_field, use_dpath=self.use_query) old_value = dict_get( instance, from_field, use_dpath=self.use_query, default=self.get_default, not_exist_ok=self.not_exist_ok, ) except TypeError as e: raise TypeError(f"Failed to get {from_field} from {instance}") if self.process_every_value:298 unmodified lines return cls.cache[artifact_identifier]
class ApplyValueOperatorsField(StreamInstanceOperator, ArtifactFetcherMixin):class ApplyOperatorsField(StreamInstanceOperator, ArtifactFetcherMixin): """ Applies value operators to each instance in a stream based on specified fields.
3 unmodified lines default_operators (List[str]): A list of default operators to be used if no operators are found in the instance. """
value_field: str inputs_fields: str operators_field: str default_operators: List[str] = None
10 unmodified lines
for name in operator_names: operator = self.get_artifact(name) instance = operator(instance, self.value_field) for field in self.inputs_fields: value = instance[field] if isinstance(value, list): instance[field] = [operator.process(v) for v in value] else: instance[field] = operator.process(instance[field])
return instance
operators.py+17-4