pynwb icon indicating copy to clipboard operation
pynwb copied to clipboard

Error when adding a list of lists to the trials colums of an nwb file

Open Ahad-Allen opened this issue 4 years ago • 3 comments

Description

When using the add_trial_column functionality to add a list of lists, I receive the following error message when exporting the generated NWB file:

    raise TypeError("Can't broadcast %s -> %s " % (target_shape, self.mshape))
TypeError: Can't broadcast (70931,) -> (70931, 1)

Steps to Reproduce

To give more context for the error: I am adding the list of lists to the file using the following code:

if i in eval_literals:
    counter = 0
    data_list = []
    for j in csv_info[i]:
        datum = (ast.literal_eval(csv_info[i][counter]))
        if isinstance(datum, float):
            datum_new = []
            datum_new.append(datum)
            datum = datum_new
        counter += 1
        data_list.append(datum)
    input_nwb.add_trial_column(name=i, description=i, data=data_list)

Each element in the list is a set of values represented as a string within a csv file as follows: [value1,value2,value3] or [value]. In order to prevent the list from being read as a string, I am using liter_eval to represent it as a list of floats. Additionally, I am exporting the generated nwb as follows:

with NWBHDF5IO(write_nwb_path, mode='w') as export_io:
    export_io.export(src_io=io, nwbfile=input_nwb)

I am running on a windows machine using python 3.7.11 Also, it's entirely possible this is a case of user error rather than an error with pynwb. If that's the case, I would greatly appreciate help on the appropriate way to add such values to trials table of an nwb.

Ahad-Allen avatar Dec 24 '21 05:12 Ahad-Allen

@Ahad-Allen I would like to help but I can't quite understand what you are trying to accomplish. It would really help us if the code to reproduce the error is entirely self-contained, i.e. it does not depend on any external CSV files so that I can run the exact code you provide and get the same error. Could you hard-code a few values in the code so that we do not rely on this external CSV file? Could you then pare down the code as much as you can to the minimum self-contained code that reproduces this error?

bendichter avatar Dec 24 '21 13:12 bendichter

@Ahad-Allen I would like to help but I can't quite understand what you are trying to accomplish. It would really help us if the code to reproduce the error is entirely self-contained, i.e. it does not depend on any external CSV files so that I can run the exact code you provide and get the same error. Could you hard-code a few values in the code so that we do not rely on this external CSV file? Could you then pare down the code as much as you can to the minimum self-contained code that reproduces this error?

Thanks for the response Ben! Apologies for the delay in getting back to you, I was previously off for the holidays. I'll work on creating a self contained version of the code to help clarify the code for you.

Ahad-Allen avatar Jan 03 '22 17:01 Ahad-Allen

Would you maybe be able to upload one of these CSV files?

bendichter avatar Feb 23 '22 20:02 bendichter