Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`__init__` and `__call__` methods are not cloudpickled

未关闭
#464 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
pandas, python
领域
backend

调研方向

首先运行该 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudpipe/cloudpickle 的其他 Issue

查看 cloudpipe/cloudpickle 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。