Skip to content

Support MATLAB Table and Timetable saved with MATLAB >2025a - #67

Open
foreverallama wants to merge 6 commits into
mainfrom
mat-to-table-v5
Open

foreverallama wants to merge 6 commits into
mainfrom
mat-to-table-v5

Conversation

@foreverallama

Copy link
Copy Markdown
Owner

Since 2025a, MATLAB increased the variable name character limit for their tables to 2048 characters. This is accompanied by new properties useVariableNames2048, with the legacy field carrying a truncated name.

This PR bumps the load version for MATLAB tables to v5 by supporting these new fields with long variable names and dimension names. The save version remains v4.

As a side note, this probably means that v4 does not support long variable names. I am yet to test this out by saving from Python with Table v4 and loading back in MATLAB.

@foreverallama

Copy link
Copy Markdown
Owner Author

MATLAB release notes states the following:

In tables and timetables, the maximum allowed length of dimension and variable names has increased
to 2048 characters. This length matches the updated maximum identifier length, which you can query
by using the namelengthmax function.
If you save a table or timetable with long dimension or variable names to a MAT file, then you can
load it into a MATLAB release before R2025a. However, the earlier MATLAB release truncates the
long dimension and variable names in the table or timetable to 63 characters.

I'll be checking with timetable as well before proceeding further with this PR. Regarding the compatibility, I tried out the following:

long_name_1 = "X" * 100
long_name_2 = "Y" * 100

df = pd.DataFrame({
    long_name_1: [10.0, 20.0, 30.0],
    long_name_2: [100.0, 200.0, 300.0],
})

mdict = {"table_var_names": df}
save_to_mat("test.mat", mdict, version="v7")

I was surprisingly able to load this with the full variable name with MATLAB 2025b. Not sure how the behaviour would change with earlier releases (<2025a) though. Hopefully it doesn't error out and just truncates the length.

@foreverallama foreverallama changed the title Support MATLAB Table saved with version v5 (MATLAB >2025a) Support MATLAB Table and Timetable saved with MATLAB >2025a Sep 20, 2026
@foreverallama

Copy link
Copy Markdown
Owner Author

Timetable has also bumped to version 7, with the same changes as Table. This PR now supports loading both Tables and Timetables saved with MATLAB >2025a.

The tests should fail because of NumPy 2.5, so I'll keep this open till that is fixed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant