rsagroup / rsatoolbox

Python library for Representational Similarity Analysis
MIT License
188 stars 37 forks source link

`load_rdm()` to accept file handle #373

Open caiw opened 12 months ago

caiw commented 12 months ago

load_rdm(filename, filetype) actually accepts an open file passed in as filename, though this is not documented. In other words, the following works:

with open(rdm_path, mode="rb") as f:
    rdm = load_rdm(f, file_type="hdf5")

However the documentation says the file_type can be None (and is by default), in which case it is inferred from the extension of the filename. But this of course breaks when supplying a file handle because the inference is done by inspecting the filename string.

The same is true of with open(rdm_path, mode="wb") as f: RDMs.save(filename=f), but the file type inference doesn't break because it has a default value of 'hdf5'.

I propose load_rdms() and RDMs.save() both be bolstered to officially accept file handles (and Paths) in their first arguments, and the documentation and error messages slightly rewritten to make it clear when filetype is optional.

JasperVanDenBosch commented 12 months ago

Seconded