List values in spreadsheets

I have a trial spreadsheet with values such as “[0, 0, 0, 0, 0, 0, 1, 1]” in column “test” that are being read by an experiment. In PsychoPy (Python), the len(test) is 8, suggesting that this value is treated as a list. In PsychoJS (Javascript), the test.length is 24 - it appears to be treated as a string. Printing out the elements of test indeed prints ‘[’, ‘0’, ‘,’, etc as the components.

I believe that this is a bug. According to the status of PsychoJS, CSV files are in the “done” category, while XLSX is in the “not done” column. However, I tested both formats, and the results are the same.

PsychoPy = 2020.2.4

Have you tried taking the commas out?

I think there’s something about needing to explicitly tell JS that the contents of the cell is a list. You could try array(test) or test.split(",")

For the time being, I’m using eval(test) as a workaround in the Javascript code only. The other suggested solutions don’t work.

@arnon_weinberg, thanks for bringing up such interesting issues (no irony).
I never tried putting arrays in spreadsheets for use in PsychoPy and PsychoJS, but I would have expected the behavior you report. A format like [0,1,2,3] happens to be the way you describe an array in JS and Python, but it doesn’t have meaning to CSV/XLSX, so treating it like a string that you need to parse into an array could actually be quite robust. I’ll bring this topic up in our daily meeting to see how the PsychoPy people feel about it.

One suggestion for your workaround: consider using JSON.parse instead of eval.

1 Like

Thanks @thomas_pronk. Also note that when saving csv/xlsx, both PsychoPy and PsychoJS use this array format. It is only when reading csv/xlsx that the behaviour is inconsistent between PsychoPy and PsychoJS.

Meanwhile I had a chat with my fellow developers. Syncing up the behavior of PsychoJS with PsychoPy is already in the scaffolds; we’ll have the same feature (reading in table cells as arrays) in one of the next releases.