Upload operators.py with huggingface_hub
Browse files249 unmodified lines2502512522532542552562572582592602612622632645 unmodified lines270271272273274275276277278279280249 unmodified linesto_field: str = NonPositionalField(required=True)def function_to_str(self, function: Callable) -> str:return function.__qualname__def str_to_function(self, function_str: str) -> Callable:splitted = function_str.split(".", 1)if len(splitted) == 1:return getattr(__builtins__, function_str)else:module_name, function_name = splittedif module_name in globals():obj = globals()[module_name]else:obj = importlib.import_module(module_name)5 unmodified linessuper().prepare()if isinstance(self.function, str):self.function = self.str_to_function(self.function)def get_init_dict(self):result = super().get_init_dict()result["function"] = self.function_to_str(self.function)return resultdef process(self, instance: Dict[str, Any], stream_name: str = None) -> Dict[str, Any]:argv = [instance[arg] for arg in self._argv]249 unmodified lines2502512522532542552562572582592602612622632642652662672682692702712722732742752762775 unmodified lines283284285286287288289249 unmodified linesto_field: str = NonPositionalField(required=True)def function_to_str(self, function: Callable) -> str:parts = []if hasattr(function, "__module__"):parts.append(function.__module__)if hasattr(function, "__qualname__"):parts.append(function.__qualname__)else:parts.append(function.__name__)result = ".".join(parts)return resultdef str_to_function(self, function_str: str) -> Callable:splitted = function_str.split(".", 1)if len(splitted) == 1:return __builtins__[module_name]else:module_name, function_name = splittedif module_name in __builtins__:obj = __builtins__[module_name]elif module_name in globals():obj = globals()[module_name]else:obj = importlib.import_module(module_name)5 unmodified linessuper().prepare()if isinstance(self.function, str):self.function = self.str_to_function(self.function)self._init_dict["function"] = self.function_to_str(self.function)def process(self, instance: Dict[str, Any], stream_name: str = None) -> Dict[str, Any]:argv = [instance[arg] for arg in self._argv]
operators.py+17-8