A system function that could tell you how many rows and how many columns a dataset has would be really useful. Thoughts?
Why do you need a system function for this?
You can just ask the instance you have directly. PyDatasets will also accurately report row count to the Python len()
builtin.
In an expression context, the len()
builtin will also work for datasets.
There are actually a lot of great functions that a dataset has inherently.
data = system.dataset.toDataSet(["Column 1", "Column 2"],[[100, 200]])
print data.getRowCount()
print data.getColumnCount()
print data.getColumnNames()
As Paul said, you can certainly use pythonic features as well with a PyDataSet.
dataset = system.dataset.toDataSet(["Column 1", "Column 2"],[[100, 200]])
data = system.dataset.toPyDataSet(dataset)
print len(data) # Row Count
print len(data[0]) # Column Count
It's possible someday we'll also support data[0].keys()
to get the column names, but we don't have support yet as of today.
There are also properties:
data = system.dataset.toDataSet(["Column 1", "Column 2"],[[100, 200]])
print data.rowCount
print data.columnCount
print data.columnNames
Power user tip:
Most objects that have "getter" functions in Ignition's objects provide access to those same functions using property accessors.
data.getRowCount() and data.rowCount hit the same function behind the scenes.
You can try it on other get*() functions in Ignition's objects too!
These are also more performant.