Too 'cute' to embed column names as keyword arguments?
One downside is embedding column names with spaces:
from collections import OrderedDict
columns = OrderedDict()
columns["Column 1"] = int
columns["Column 2"] = str
I suppose you could call builder(), and then I could add setters for column names and column types to the builder object; that way you can get the terser syntax if you don't need exotic column names, but it's available if you do.
Meh. DatasetBuilder gives you total control in a very terse package. Maybe just expose it in system. so we don't have to import it. (With the java class names suited to datasets for use with its colTypes method.) Its methods are chainable so one-liners are easy.
system.dataset.equals(dataset, dataset): Boolean
Returns True if both input datasets have the same columns, with the same types, and the same values.
system.dataset.valuesEqual(dataset, dataset): Boolean
Returns True if both input datasets have the same number of rows/columns, and those rows/columns have the same values in the same places.
system.dataset.columnsEqual(dataset, dataset, ignoreCase=False, includeTypes=True): Boolean
Returns True if both input datasets have the same column definitions. Use the optional keyword arguments to make the behavior more lenient.
Returns a wrapped DatasetBuilder. Provided keyword arguments (if any) are used as column names; the values should be Java or Python types, or the 'short codes' accepted by system.dataset.fromCSV:
In addition, the colTypes function can now be called with the same short codes, or common Python types (e.g. str instead of java.lang.String).
Great stuff @PGriffith . The string for column types is better than my original suggestion and more consistent with what Ignition already uses.
One question re: system.dataset.equals vs system.dataset.valueEquals - first one is same columns/types/values, and the second is same rows/columns, but not type. Is it possible then for two datasets of differing row numbers to return true from system.dataset.equals? Just trying to understand a situation where system.dataset.equals would return true but system.dataset.valueEquals would return false and vice versa.
The implementation of equals is literally: return ds1 === ds2 || (columnsEqual(ds1, ds2) && valuesEqual(ds1, ds2))
So, the only way you'd have equals return false but valuesEqual return true is if the second dataset had the same column types, rows, data, but different column names. I figure that's unlikely, but potentially useful.
This was the idea I was talking about. Is it possible to add this change into the extensions module? Or at least another function to return just the non-default config on the UDT instance and not in the definition? This is a big issue when trying to script tag changes
Recently I had to convert something to an iso format. Currnetly you would have to do it manually system.date.format but other date libraries (like datetime for instance) have a function .isoformat() since ISO is so common. So maybe that as an additional date function? Something like system.date.isoFormat(someDate)?
I know it's simple and only saves a handful of lines of code but we are talking about convenience functions. Just a thought. I don't know how others feel about this one.
Sorry for the sin of double posting but I ran into a dataset one that I would love to have.
I am trying to write tests now and I have to refer to datasets that come in and get referred in my functions. In my test function I don't want to have to have to go out to the window and grab a dataset. This I guess falls under meta programming but it would be nice if we could reverse engineer any dataset into a script that creates the dataset? For example say I have a dataset
Then running something like system.datset.getScript(ds)
Just want to give back to the community a little bit since you all have helped me so much. I know it's something I specifically asked for but maybe it will help someone else too - a way to take a dataset and convert it to code that would generate an identical dataset. I am using this so I can take datasets that are in windows and convert it to code for my testing functions easily (I have a lot of datasets to do it for)
columnNames = [str(column) for column in ds.columnNames]
rowData = 
for cur_row in range(ds.getRowCount()):
row = 
for cur_col in range(ds.getColumnCount()):
value = ds.getValueAt(cur_row, cur_col)
if isinstance(value, unicode) or isinstance(value, str):
value = str(value)
code = 'system.dataset.toDataSet(%s, %s)'%(columnNames, rowData)
It works pretty well for me and the types seem to come through as well at least on my initial tests which is nice. I'm sure there is room for improvement but this works well enough for me atm.