IndexError: Row 0 doesn't have the same number of columns as header list

This is driving me crazy. What am I doing wrong? I am trying to do something like this and keep getting this error. I'm trying to do this.
modesHeader=['Mode1','Mode2','Mode3','Mode4']
modesHeaderEco=['Mode1','Mode2']
modesEco=
for mode in traits['sdm.devices.traits.ThermostatEco']['availableModes']:
modesEco.append(mode)
modes=
for mode in traits['sdm.devices.traits.ThermostatMode']['availableModes']:
modes.append(mode)
print len(modes),len(modesHeader)
print len(modesEco),len(modesHeaderEco)
modeEcoDataset=system.dataset.toDataSet(modesHeaderEco,modesEco)
modeDataset=system.dataset.toDataSet(modesHeader,modes)
And I keep getting the error. So for a sanity check I did this and got the same error.
headers=['thing','thing2']
items=['toby','steak']
dataset=system.dataset.toDataSet(headers,items)

Put each individual item in brackets ['item1'], ['item2']

Thank you for the input but that did not seem to fix the problem.

You don't provide any printouts to go with your code, so it is not entirely clear what your traits dictionary is yielding. Anyways, the key is that system.dataset.toDataSet(headers, rows) needs headers to be a list of strings that will become your column names, and rows must be a list of lists, where the outer list represents rows, and in the inner lists are the column values for each row. Those inner lists must be the same length as headers.

This is valid:

ds = system.dataset.toDataSet(['a', 'b', 'c'], [[1, 'w', 2], [3, 'x', 4], [5, 'y', 6], [7, 'z', 8]])

Notice the nested structure of rows. Organize your code to do the same.

{ ps. Edit your comment, highlight all of the code, and click the "Preformatted Text" button in the comment editor. This will make a code block that will preserve code formatting for us to see. }

I did end up doing this

modes=system.dataset.toDataSet(['Modes'], [[x] for x in traits['sdm.devices.traits.ThermostatMode']['availableModes']])
	modesEco=system.dataset.toDataSet(['Modes'], [[x] for x in traits['sdm.devices.traits.ThermostatEco']['availableModes']])