1

I have read following Q&As:

How to specify min_itemsize for an index column

Pandas pytable: how to specify min_itemsize of the elements of a MultiIndex

but still cannot make my toy example work:

with pd.HDFStore('teststore.h5') as store:
    chunk = pd.DataFrame({"V1":["a","b","c","d","e"], "data":np.arange(5)}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={chunk.index.name: 32 })

    chunk = pd.DataFrame({"V1":["aaaah!!!"], "data": 3}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={chunk.index.name: 32 })

returns: ValueError: min_itemsize has the key [V1] which is not an axis or data_column, while:

with pd.HDFStore('teststore.h5') as store:
    chunk = pd.DataFrame({"V1":["a","b","c","d","e"], "data":np.arange(5)}).set_index(["V1"])
    store.append("gr1", chunk, min_itemsize={"index": 32 })

    chunk = pd.DataFrame({"V1":["aaaah!!!"], "data": 3}).set_index(["V1"])
    store.append("gr1",chunk, min_itemsize={"index": 32 })

returns:

ValueError: Trying to store a string with len [8] in [index] column but
this column has a limit of [1]!
Consider using min_itemsize to preset the sizes on these columns

What is a correct / working way?

Community
  • 1
  • 1
Dima Lituiev
  • 12,544
  • 10
  • 41
  • 58

0 Answers0