# Buggy code
def build_fetch_tileable(tileable, coarse=False):
    if coarse or tileable.is_coarse():
        chunks = None
    else:
        chunks = []
        for c in tileable.chunks:
            fetch_chunk = build_fetch_chunk(c, index=c.index)
            chunks.append(fetch_chunk)

    tileable_op = tileable.op
    params = tileable.params.copy()

    new_op = get_fetch_op_cls(tileable_op)(**params)
    return new_op.new_tileables(
        None,
        chunks=chunks,
        nsplits=tileable.nsplits,
        _key=tileable.key,
        _id=tileable.id,
        **params,
    )[0]


# Traceback (TypeError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 112, in mars.actors.core._FunctionActor.on_receive
File "mars/actors/core.pyx", line 114, in mars.actors.core._FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 335, in execute_graph
self.prepare_graph(compose=compose)
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 475, in prepare_graph
td = self.tile_fetch_tileable(tileable)
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 936, in tile_fetch_tileable
fetch_graph = deserialize_graph(graph_ref.build_fetch_graph(tileable_key))
File "mars/actors/core.pyx", line 65, in mars.actors.core.ActorRef.__getattr__._mt_call
File "mars/actors/core.pyx", line 37, in mars.actors.core.ActorRef.send
File "mars/actors/pool/gevent_pool.pyx", line 179, in mars.actors.pool.gevent_pool.ActorContext.send
File "mars/actors/pool/gevent_pool.pyx", line 754, in mars.actors.pool.gevent_pool.Communicator.send
File "mars/actors/pool/gevent_pool.pyx", line 755, in mars.actors.pool.gevent_pool.Communicator.send
File "mars/actors/pool/gevent_pool.pyx", line 750, in mars.actors.pool.gevent_pool.Communicator._send
File "mars/actors/pool/gevent_pool.pyx", line 657, in mars.actors.pool.gevent_pool.Communicator._dispatch
File "mars/actors/pool/gevent_pool.pyx", line 682, in mars.actors.pool.gevent_pool.Communicator._send_local
File "src/gevent/greenlet.py", line 709, in gevent._greenlet.Greenlet.get
File "src/gevent/greenlet.py", line 317, in gevent._greenlet.Greenlet._raise_exception
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/_compat.py", line 47, in reraise
raise value.with_traceback(tb)
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 72, in mars.actors.pool.gevent_pool.MessageContext.result
File "mars/actors/pool/gevent_pool.pyx", line 73, in mars.actors.pool.gevent_pool.MessageContext.result
File "src/gevent/event.py", line 344, in gevent._event.AsyncResult.result
File "src/gevent/event.py", line 268, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 286, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 266, in gevent._event.AsyncResult._raise_exception
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/_compat.py", line 47, in reraise
raise value.with_traceback(tb)
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 112, in mars.actors.core._FunctionActor.on_receive
File "mars/actors/core.pyx", line 114, in mars.actors.core._FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 928, in build_fetch_graph
return serialize_graph(graph)
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 217, in serialize_graph
ser_graph = graph.to_pb().SerializeToString()
File "mars/graph.pyx", line 431, in mars.graph.DirectedGraph.to_pb
File "mars/serialize/core.pyx", line 563, in mars.serialize.core.Serializable.to_pb
File "mars/serialize/core.pyx", line 547, in mars.serialize.core.Serializable.serialize
File "mars/serialize/core.pyx", line 665, in mars.serialize.core.Provider.serialize_model
File "mars/serialize/core.pyx", line 141, in mars.serialize.core.Field.serialize
File "mars/serialize/core.pyx", line 142, in mars.serialize.core.Field.serialize
File "mars/serialize/pbserializer.pyx", line 476, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
File "mars/serialize/core.pyx", line 547, in mars.serialize.core.Serializable.serialize
File "mars/serialize/core.pyx", line 665, in mars.serialize.core.Provider.serialize_model
File "mars/serialize/core.pyx", line 141, in mars.serialize.core.Field.serialize
File "mars/serialize/core.pyx", line 142, in mars.serialize.core.Field.serialize
File "mars/serialize/pbserializer.pyx", line 447, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
File "mars/serialize/core.pyx", line 142, in mars.serialize.core.Field.serialize
File "mars/serialize/pbserializer.pyx", line 467, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
File "mars/serialize/core.pyx", line 547, in mars.serialize.core.Serializable.serialize
File "mars/serialize/core.pyx", line 665, in mars.serialize.core.Provider.serialize_model
File "mars/serialize/core.pyx", line 141, in mars.serialize.core.Field.serialize
File "mars/serialize/core.pyx", line 142, in mars.serialize.core.Field.serialize
File "mars/serialize/pbserializer.pyx", line 485, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
File "mars/serialize/pbserializer.pyx", line 428, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_value
File "mars/serialize/pbserializer.pyx", line 365, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_typed_value
File "mars/serialize/pbserializer.pyx", line 246, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_tuple
File "mars/serialize/pbserializer.pyx", line 428, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_value
File "mars/serialize/pbserializer.pyx", line 365, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_typed_value
File "mars/serialize/pbserializer.pyx", line 246, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_tuple
File "mars/serialize/pbserializer.pyx", line 428, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_value
File "mars/serialize/pbserializer.pyx", line 338, in mars.serialize.pbserializer.ProtobufSerializeProvider._set_typed_value
TypeError: nan has type float, but expected one of: int, long
2019-05-21T10:36:49Z <Greenlet at 0xc20a0d598: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0xc20d32138>> failed with TypeError

# Fixed code
def build_fetch_tileable(tileable, coarse=False):
    if coarse or tileable.is_coarse():
        chunks = None
    else:
        chunks = []
        for c in tileable.chunks:
            fetch_chunk = build_fetch_chunk(c, index=c.index)
            chunks.append(fetch_chunk)

    tileable_op = tileable.op
    params = tileable.params.copy()

    new_op = get_fetch_op_cls(tileable_op)()
    return new_op.new_tileables(
        None,
        chunks=chunks,
        nsplits=tileable.nsplits,
        _key=tileable.key,
        _id=tileable.id,
        **params,
    )[0]