Skip to content

BUG: DataFrame.to_hdf cannot handle data_columns for a column named 'index' #41437

Open
@Pierre-Bartet

Description

@Pierre-Bartet

It seems impossible to save a DataFrame as a HDF file when:

  • One of the column is named 'index'
  • data_columns=['index']
  • format='table'

The same also happens using HDFStore + put

>>> import pandas as pd
>>> df = pd.DataFrame({'column_1': [1, 2], 'index': [3, 4]})
>>> df.index.name = 'something_else'  # Optionnaly
>>> df.to_hdf(path, 'data', format='table', data_columns=['index'])
...
in write_data(self, chunksize, dropna)
   4293         bvalues = []
   4294         for i, v in enumerate(values):
-> 4295             new_shape = (nrows,) + self.dtype[names[nindexes + i]].shape
   4296             bvalues.append(values[i].reshape(new_shape))
   4297

IndexError: tuple index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions