# Buggy code
def load(tag, creds=None, session_creds=True) -> Dataset:
    """Load a dataset from repository using given url and credentials (optional)"""
    fs, path = _load_fs_and_path(tag, creds, session_creds=session_creds)
    fs: fsspec.AbstractFileSystem = fs
    path_2 = f"{path}/meta.json"
    if not fs.exists(path):
        from hub.exceptions import DatasetNotFound

        raise DatasetNotFound(tag)

    with fs.open(path_2, "r") as f:
        ds_meta = json.loads(f.read())

    for name in ds_meta["tensors"]:
        assert fs.exists(f"{path}/{name}"), (
            f"Tensor {name} of {tag} dataset does not exist"
        )
    if ds_meta["len"] == 0:
        logger.warning("The dataset is empty (has 0 samples)")
        return Dataset(
            {
                name: Tensor(
                    tmeta,
                    dask.array.from_array(
                        np.empty(shape=(0,) + tuple(tmeta["shape"][1:]), dtype="uint8"),
                    ),
                )
                for name, tmeta in ds_meta["tensors"].items()
            },
            metainfo=ds_meta.get("metainfo"),
        )
    len_ = ds_meta["len"]

    # added reverse compatibility for previous versions
    for name, tmeta in ds_meta["tensors"].items():
        if "chunksize" not in tmeta:
            tmeta["chunksize"] = 1

    return Dataset(
        {
            name: Tensor(
                tmeta,
                _dask_concat(
                    [
                        dask.array.from_delayed(
                            dask.delayed(_numpy_load)(
                                fs,
                                f"{path}/{name}/{i}.npy",
                                codec_from_name(tmeta.get("dcompress")),
                            ),
                            shape=(min(tmeta["chunksize"], len_ - i),)
                            + tuple(tmeta["shape"][1:]),
                            dtype=tmeta["dtype"],
                        )
                        for i in range(0, len_, tmeta["chunksize"])
                    ]
                ),
            )
            for name, tmeta in ds_meta["tensors"].items()
        },
        metainfo=ds_meta.get("metainfo"),
    )


# Traceback (ValueError)
Traceback (most recent call last):
File "hub/compute/tests/test_transform.py", line 284, in <module>
test_threaded()
File "hub/compute/tests/test_transform.py", line 88, in test_threaded
create_classification_dataset(ds_init).store(
File "/Users/davitb/Git/Hub/hub/compute/transform.py", line 246, in store
ds = self.upload(results, url=url, token=token, progressbar=progressbar)
File "/Users/davitb/Git/Hub/hub/compute/transform.py", line 177, in upload
list(self.map(upload_chunk, index_batched_values))
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/pathos/threading.py", line 134, in map
return _pool.map(star(f), zip(*args)) # chunksize
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/multiprocess/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/multiprocess/pool.py", line 771, in get
raise self._value
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/multiprocess/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/multiprocess/pool.py", line 48, in mapstar
return list(map(*args))
File "/Users/davitb/Library/Python/3.8/lib/python/site-packages/pathos/helpers/mp_helper.py", line 15, in <lambda>
func = lambda args: f(*args)
File "/Users/davitb/Git/Hub/hub/compute/transform.py", line 167, in upload_chunk
ds[key, i * length + k] = el
File "/Users/davitb/Git/Hub/hub/api/dataset.py", line 316, in __setitem__
self._tensors[subpath][slice_list] = value
File "/Users/davitb/Git/Hub/hub/store/dynamic_tensor.py", line 207, in __setitem__
self._dynamic_tensor[slice_[0]]
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 571, in __getitem__
return self.get_basic_selection(selection, fields=fields)
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 696, in get_basic_selection
return self._get_basic_selection_nd(selection=selection, out=out,
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 739, in _get_basic_selection_nd
return self._get_selection(indexer=indexer, out=out, fields=fields)
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 1028, in _get_selection
self._chunk_getitem(chunk_coords, chunk_selection, out, out_selection,
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 1649, in _chunk_getitem
self._process_chunk(out, cdata, chunk_selection, drop_axes,
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 1592, in _process_chunk
chunk = self._decode_chunk(cdata)
File "/usr/local/lib/python3.8/site-packages/zarr/core.py", line 1802, in _decode_chunk
chunk = chunk.reshape(self._chunks, order=self._order)
ValueError: cannot reshape array of size 0 into shape (50,3)

# Fixed code
def load(tag, creds=None, session_creds=True) -> Dataset:
    """Load a dataset from repository using given url and credentials (optional)"""
    fs, path = _load_fs_and_path(tag, creds, session_creds=session_creds)
    fs: fsspec.AbstractFileSystem = fs
    path_2 = f"{path}/meta.json"
    if not fs.exists(path):
        raise HubDatasetNotFoundException(tag)

    with fs.open(path_2, "r") as f:
        ds_meta = json.loads(f.read())

    for name in ds_meta["tensors"]:
        assert fs.exists(f"{path}/{name}"), (
            f"Tensor {name} of {tag} dataset does not exist"
        )

    if "dask" not in sys.modules:
        raise ModuleNotInstalledException("dask")
    else:
        import dask
        import dask.array

        global dask

    if ds_meta["len"] == 0:
        logger.warning("The dataset is empty (has 0 samples)")

        return Dataset(
            {
                name: Tensor(
                    tmeta,
                    dask.array.from_array(
                        np.empty(shape=(0,) + tuple(tmeta["shape"][1:]), dtype="uint8"),
                    ),
                )
                for name, tmeta in ds_meta["tensors"].items()
            },
            metainfo=ds_meta.get("metainfo"),
        )
    len_ = ds_meta["len"]

    # added reverse compatibility for previous versions
    for name, tmeta in ds_meta["tensors"].items():
        if "chunksize" not in tmeta:
            tmeta["chunksize"] = 1

    return Dataset(
        {
            name: Tensor(
                tmeta,
                _dask_concat(
                    [
                        dask.array.from_delayed(
                            dask.delayed(_numpy_load)(
                                fs,
                                f"{path}/{name}/{i}.npy",
                                codec_from_name(tmeta.get("dcompress")),
                            ),
                            shape=(min(tmeta["chunksize"], len_ - i),)
                            + tuple(tmeta["shape"][1:]),
                            dtype=tmeta["dtype"],
                        )
                        for i in range(0, len_, tmeta["chunksize"])
                    ]
                ),
            )
            for name, tmeta in ds_meta["tensors"].items()
        },
        metainfo=ds_meta.get("metainfo"),
    )