Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`__init__` and `__call__` methods are not cloudpickled

Đang mở
#464 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
pandas, python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu bằng cách chạy reproducer của issue cho wrapt và pandas, sau đó kiểm tra cách cloudpickle xử lý các hàm được decorator và các lớp wrapper trong quá trình dumps và loads. Công việc hoàn tất khi callable đã được deserialize vẫn giữ nguyên hành vi của call và init của wrapper, bao gồm cả kết quả số lượng hàng được hiển thị trong ví dụ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
1.9k
Fork
197
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cloudpipe/cloudpickle

Tất cả issue của cloudpipe/cloudpickle

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.