Upload operators.py with huggingface_hub
Browse files143 unmodified lines14414514614714814925 unmodified lines175176177178179180181298 unmodified lines4804814824834844854863 unmodified lines49049149249349449549610 unmodified lines507508509510511512513143 unmodified linesfield_to_field: Optional[Union[List[Tuple[str, str]], Dict[str, str]]] = Noneprocess_every_value: bool = Falseuse_query: bool = Falsedef verify(self):super().verify()25 unmodified linesdef 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)except TypeError as e:raise TypeError(f"Failed to get {from_field} from {instance}")if self.process_every_value:298 unmodified linesreturn cls.cache[artifact_identifier]class ApplyValueOperatorsField(StreamInstanceOperator, ArtifactFetcherMixin):"""Applies value operators to each instance in a stream based on specified fields.3 unmodified linesdefault_operators (List[str]): A list of default operators to be used if no operators are found in the instance."""value_field: stroperators_field: strdefault_operators: List[str] = None10 unmodified linesfor name in operator_names:operator = self.get_artifact(name)instance = operator(instance, self.value_field)return instance143 unmodified lines14414514614714814915015125 unmodified lines177178179180181182183184185186187188189298 unmodified lines4884894904914924934943 unmodified lines49849950050150250350410 unmodified lines515516517518519520521522523524525526143 unmodified linesfield_to_field: Optional[Union[List[Tuple[str, str]], Dict[str, str]]] = Noneprocess_every_value: bool = Falseuse_query: bool = Falseget_default: Any = Nonenot_exist_ok: bool = Falsedef verify(self):super().verify()25 unmodified linesdef 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,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 linesreturn cls.cache[artifact_identifier]class ApplyOperatorsField(StreamInstanceOperator, ArtifactFetcherMixin):"""Applies value operators to each instance in a stream based on specified fields.3 unmodified linesdefault_operators (List[str]): A list of default operators to be used if no operators are found in the instance."""inputs_fields: stroperators_field: strdefault_operators: List[str] = None10 unmodified linesfor name in operator_names:operator = self.get_artifact(name)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