I am trying a create a new dataset from an existing one.
I first tried using the following code: system.dataset.toDataSet(data.getColumnNames(), new_data)
But I get a TypeError: toDataSet(): 1st arg can't be coerced to org.python.core.PySequence
I then found another solution: system.dataset.toDataSet(system.dataset.getColumnHeaders(data), new_data)
Which works.
Is it normal that data.getColumnNames() does not return an object of the same type as system.dataset.getColumnHeaders(data)?
.getColumnNames() is a java method of the Dataset interface, and is only required to return a java List<String>. You can wrap it in list() to make it deliver a python type. You can save some typing and some speed by using list(data.columnNames), taking advantage of jython's recognition of NetBeans-style getters as properties.
Yes, it's completely normal that it returns an immutable object (UnmodifiableRandomAccessList). You could system.dataset.toDataSet(list(data.getColumnNames()), new_data)
I would also maintain, personally, that toDataSet should be happy to accept any iterable of strings for the column names; the check for "PySequence" (an internal Jython type) is too strict.