Git Product home page Git Product logo

Comments (4)

cpcloud avatar cpcloud commented on August 29, 2024 1

After a bit of hacking, I got this working:

In [1]: from ibis.interactive import *

In [2]: @ibis.udf.scalar.python
   ...: def add_one(x: int) -> int:
   ...:     return x + 1
   ...:

In [3]: import cloudpickle

In [4]: cloudpickle.loads(cloudpickle.dumps(add_one))
Out[4]: <function __main__.add_one(x: int) -> int>

from ibis.

jstammers avatar jstammers commented on August 29, 2024

From looking into this further, I think this is related to the fact that cloudpickle doesn't serialize functions with type annotations e.g. cloudpipe/cloudpickle#541.

I see the same error with the following

@ibis.udf.scalar.python
def add_one(x: int) -> int:
    return x + 1

with open("func.pkl", "wb") as f:
    cloudpickle.dump(add_one, f)

with open("func.pkl", "rb") as f:
    loaded_model = cloudpickle.load(f)

from ibis.

cpcloud avatar cpcloud commented on August 29, 2024

cloudpickle does seem to preserve annotations (I think cloudpipe/cloudpickle#541 is about annotating the cloudpickle library itself, not about supporting them in pickling/unpickling).

Perhaps there's an issue on our side.

In [1]: import cloudpickle

In [2]: def add_one(x: int) -> int:
   ...:     return x + 1
   ...:

In [3]: func = cloudpickle.loads(cloudpickle.dumps(add_one))

In [4]: func
Out[4]: <function __main__.add_one(x: int) -> int>

In [5]: func.__annotations__
Out[5]: {'x': int, 'return': int}

from ibis.

jstammers avatar jstammers commented on August 29, 2024

To add to this issue, I've been investigating using pickle instead, but have hit a blocker with a case statement

import pickle
from ibis import _
import ibis

c = ibis.case().when(_.s == 1, "EXACT").when(True, "DIFFERENT").end()

pickle.loads(pickle.dumps(c)) 

raises

PicklingError: Can't pickle <function _finish_searched_case at 0x78fdf8061900>: it's not the same object as ibis.expr.builders._finish_searched_case

I am able to pickle/unpickle this using cloudpickle however

from ibis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.