`__init__` and `__call__` methods are not cloudpickled
还没有人认领这个 Issue。
评估
调研方向
首先运行该 issue 的 wrapt 和 pandas reproducer,然后检查 cloudpickle 在 dumps 和 loads 期间如何处理经过装饰的函数和 wrapper 类。当反序列化后的 callable 保留 wrapper 的 call 和 init 行为(包括示例中显示的行数输出)时,工作即完成。
由索引模型根据 Issue 内容生成。
描述
Overwriting the logic inside __call__ method of the wrapper:
import cloudpickle
import wrapt
import pandas as pd
def _num_of_rows_wrapper() -> Any:
class FunctionWrapper(wrapt.FunctionWrapper):
def __call__(self, *args: Any, **kwargs: Any) -> Any:
dataframe = super(FunctionWrapper, self).__call__(*args, **kwargs)
num_of_rows = len(dataframe.index)
print(f"Num of rows: {num_of_rows}")
return dataframe
return FunctionWrapper
def num_of_rows():
@wrapt.decorator(proxy=_num_of_rows_wrapper())
def wrapper(wrapped, instance, args, kwargs) -> None:
return wrapped(*args, **kwargs)
return wrapper
@num_of_rows()
def prepare_data():
data = [["id1", 10], ["id2", 15], ["id3", 14]]
pandas_df = pd.DataFrame(data, columns=["id", "value"])
return pandas_df
Running the decorated function works as expected (num of rows printed):
prepare_data()
Once it is cloudpickled and loaded, __call__ gets lost (num of rows is not printed)
dump = cloudpickle.dumps(prepare_data)
loaded = cloudpickle.loads(dump)
loaded()
Same happens for the __init__ . Any suggestion for keeping those functions with cloudpickle?
- 主要语言
- Python
- 星标
- 1.9k
- 派生
- 197
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 1
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudpipe/cloudpickle 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
cloudpipe/cloudpickle#593 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 42/100
cloudpipe/cloudpickle#595 ·
-
难度 3/5 1-2 天 新手友好度 65/100
cloudpipe/cloudpickle#592 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 35/100
cloudpipe/cloudpickle#589 ·
-
难度 5/5 一周以上 新手友好度 20/100
cloudpipe/cloudpickle#587 ·
查看 cloudpipe/cloudpickle 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
gradio-app/gradio#13895 ·
维护者通常 1 天内回复
-
build-error
难度 2/5 1-3 小时 新手友好度 76/100
spack/spack-packages#6713 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ActivityWatch/activitywatch#1464 · 1 个 reaction ·
维护者通常 1 天内回复
-
[Bug]: The ckg tool drops the return type of every decorated Python method in class search results未关闭
难度 2/5 1-3 小时 新手友好度 78/100
bytedance/trae-agent#483 ·
维护者通常 1 天内回复