# Buggy code
def _execute_map(cls, ctx, op: "ProximaBuilder"):
    inp = ctx[op.tensor.key]
    out = op.outputs[0]
    pks = ctx[op.pk.key]
    proxima_type = get_proxima_type(inp.dtype)

    # holder
    holder = proxima.IndexHolder(type=proxima_type, dimension=op.dimension)
    for pk, record in zip(pks, inp):
        pk = pk.item() if hasattr(pk, "item") else pk
        holder.emplace(pk, record.copy())

    # converter
    meta = proxima.IndexMeta(
        proxima_type, dimension=op.dimension, measure_name=op.distance_metric
    )
    if op.index_converter is not None:
        converter = proxima.IndexConverter(
            name=op.index_converter, meta=meta, params=op.index_converter_params
        )
        converter.train_and_transform(holder)
        holder = converter.result()
        meta = converter.meta()

    # builder && dumper
    builder = proxima.IndexBuilder(
        name=op.index_builder, meta=meta, params=op.index_builder_params
    )
    builder = builder.train_and_build(holder)

    path = tempfile.mkstemp(prefix="proxima-", suffix=".index")[1]
    dumper = proxima.IndexDumper(name="FileDumper", path=path)
    builder.dump(dumper)
    dumper.close()

    if op.index_path is None:
        ctx[out.key] = path
    else:
        # write to external file system
        fs = get_fs(op.index_path, op.storage_options)
        filename = f"proxima-{out.index[0]}.index"
        out_path = f"{op.index_path.rstrip('/')}/{filename}"
        with fs.open(out_path, "wb") as out_f:
            with open(path, "rb") as in_f:
                # 32M
                chunk_bytes = 32 * 1024**2
                while True:
                    data = in_f.read(chunk_bytes)
                    if data:
                        out_f.write(data)
                    else:
                        break

        ctx[out.key] = filename


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 365, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/scheduler/graph.py", line 382, in execute_graph
self._execute_graph(compose=compose)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/scheduler/graph.py", line 410, in _execute_graph
self.prepare_graph(compose=compose)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 365, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/scheduler/graph.py", line 648, in prepare_graph
self._target_tileable_datas + fetch_tileables, tileable_graph)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 348, in build
tileables, tileable_graph=tileable_graph)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 262, in build
self._on_tile_failure(tileable_data.op, exc_info)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 301, in inner
raise exc_info[1].with_traceback(exc_info[2]) from None
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 242, in build
tiled = self._tile(tileable_data, tileable_graph)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 337, in _tile
return super()._tile(tileable_data, tileable_graph)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 203, in _tile
tds = on_tile(tileable_data.op.outputs, tds)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/scheduler/graph.py", line 630, in on_tile
return self.context.wraps(handler.dispatch)(first.op)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/context.py", line 72, in h
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tiles.py", line 119, in dispatch
tiled = op_cls.tile(op)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/dataframe/merge/concat.py", line 182, in tile
return cls._tile_dataframe(op)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/dataframe/merge/concat.py", line 94, in _tile_dataframe
inputs = [item.rechunk(normalized_nsplits)._inplace_tile() for item in inputs]
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/dataframe/merge/concat.py", line 94, in <listcomp>
inputs = [item.rechunk(normalized_nsplits)._inplace_tile() for item in inputs]
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/dataframe/base/rechunk.py", line 96, in rechunk
chunk_size = get_nsplits(a, chunk_size, itemsize)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tensor/rechunk/core.py", line 38, in get_nsplits
return decide_chunk_sizes(tileable.shape, chunk_size, itemsize)
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tensor/utils.py", line 551, in decide_chunk_sizes
return normalize_chunk_sizes(shape, tuple(chunk_size[j] for j in range(len(shape))))
File "/home/admin/work/tip_dev-pymars-0.6.0a3.zip/mars/tensor/utils.py", line 66, in normalize_chunk_sizes
raise ValueError('chunks shape should be of the same length, '
ValueError: chunks shape should be of the same length, got shape: 100000, chunks: (nan, nan, nan, nan, nan, nan)

# Fixed code
def _execute_map(cls, ctx, op: "ProximaBuilder"):
    inp = ctx[op.tensor.key]
    out = op.outputs[0]
    pks = ctx[op.pk.key]
    proxima_type = get_proxima_type(inp.dtype)

    # holder
    holder = proxima.IndexHolder(type=proxima_type, dimension=op.dimension)
    for pk, record in zip(pks, inp):
        pk = pk.item() if hasattr(pk, "item") else pk
        holder.emplace(pk, record.copy())

    # converter
    meta = proxima.IndexMeta(
        proxima_type, dimension=op.dimension, measure_name=op.distance_metric
    )
    if op.index_converter is not None:
        converter = proxima.IndexConverter(
            name=op.index_converter, meta=meta, params=op.index_converter_params
        )
        converter.train_and_transform(holder)
        holder = converter.result()
        meta = converter.meta()

    # builder && dumper
    builder = proxima.IndexBuilder(
        name=op.index_builder, meta=meta, params=op.index_builder_params
    )
    builder = builder.train_and_build(holder)

    path = tempfile.mkstemp(prefix="proxima-", suffix=".index")[1]
    dumper = proxima.IndexDumper(name="FileDumper", path=path)
    builder.dump(dumper)
    dumper.close()

    if op.index_path is None:
        ctx[out.key] = path
    else:
        # write to external file system
        fs = get_fs(op.index_path, op.storage_options)
        filename = f"proxima_{out.index[0]}_index"
        out_path = f"{op.index_path.rstrip('/')}/{filename}"
        with fs.open(out_path, "wb") as out_f:
            with open(path, "rb") as in_f:
                # 32M
                chunk_bytes = 32 * 1024**2
                while True:
                    data = in_f.read(chunk_bytes)
                    if data:
                        out_f.write(data)
                    else:
                        break

        ctx[out.key] = filename