data.getColumnNames() vs system.dataset.getColumnHeaders(data)

Hi,

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)?

Thanks

PS: Running Ignition 8.1.18

.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.

{ Edit: oops, list, not str. }

2 Likes

Yes, it's completely normal that it returns an immutable object (UnmodifiableRandomAccessList). You could system.dataset.toDataSet(list(data.getColumnNames()), new_data)

1 Like

Understood. I confirm wrapping in list() works. Thanks!

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.

2 Likes

If it simply declared that argument as List<>, jython would be happy to feed it any sequence.