frejanordsiek / hdf5storage

Python package to read and write a wide range of Python types to/from HDF5 formatted files. Can read/write data to the HDF5 based Matlab v7.3 MAT files.
BSD 2-Clause "Simplified" License
82 stars 24 forks source link

Strings not loaded properly when using oned_as='column' in savemat() #120

Open jeremypriest opened 2 years ago

jeremypriest commented 2 years ago

Hello Freja! First, thank you for hdf5storage - we use it extensively at my place of work.

I'm seeing a bug in v0.1.18 when I use oned_as='column' in savemat(). Here is a snippet:

import hdf5storage as hs

a = {'metadata':
         {'paths':
              {'0': 'string0',
               '1': 'string1',
               '2': 'string2'}}}

# Save the dictionary
file = 'test.mat'
hs.savemat(file, mdict=a, oned_as='column')

# Load the dictionary
b = hs.loadmat(file)

print(a)
print(b)

# Assert the original and loaded dicts match
assert a == b

I see the following printed, and the assert fails.

{'metadata': {'paths': {'0': 'string0', '1': 'string1', '2': 'string2'}}}
{'metadata': {'paths': {}}}

I notice when I swap oned_as to 'rows' from 'columns', this behavior goes away. Let me know if there is any more information I can provide!

Python version: 3.8.12 hdf5storage version: 0.1.18