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
83 stars 24 forks source link

`savemat` creates files incompatible with MATLAB on some locales #123

Closed BSchilperoort closed 1 year ago

BSchilperoort commented 2 years ago

When using savemat to write a .mat file, with a system locale such as Chinese, savemat writes a header containing Chinese characters. MATLAB is not able to read these files and fails the open the .mat file:

Error using load - Unable to read MAT-file example.mat. Not a binary MAT-file. Try load -ASCII to read as text.

The offending code is here; https://github.com/frejanordsiek/hdf5storage/blob/ec2e1e34789ad27713b860eb4de5da99817fa315/hdf5storage/__init__.py#L1711

As strftime uses the locale to determine the month and day names, these can contain characters that MATLAB cannot read;

MATLAB 7.3 MAT-file, Platform: CPython 3.8.13, Created on: 摹曛 8月 25 15:40:44 2022 HDF5 schema 1.00 .

Interestingly, Octave seems to be fine with the Chinese characters đŸ€·


Probably related to #116

Our discussion: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/issues/38

frejanordsiek commented 1 year ago

Fixed in commit 3d54b5624d6974c95ddc6a791257276072e441f5 in the 0.1.x branch. This package now forces the use of English month and day of the week names, regardless of locale.

I will be pushing a 0.1.19 bugfix release to PyPI shortly.

BSchilperoort commented 1 year ago

Nice, thanks for fixing this!