I don't see how - filterColumn will remove the type completely, and the newly generated row should work just fine. I did some testing and wasn't able to reproduce that error.
I was curious about this, so I did some benchmarking, and (not really surprisingly) setting the values-per-row is incredibly slower - many orders of magnitude as the row count increases:
Running 'zeroColumnAtOnce' on a dataset with 100 rows 10000 times took 204ms; average: 0.0204ms
Running 'zeroColumnIteratively' on a dataset with 100 rows 10000 times took 5133ms; average: 0.5133ms
Running 'zeroColumnAtOnce' on a dataset with 1000 rows 1000 times took 98ms; average: 0.098ms
Running 'zeroColumnIteratively' on a dataset with 1000 rows 1000 times took 39854ms; average: 39.854ms
And the code I used, including a slightly cleaned up version of what I originally posted:
from java.lang import Double, Float, Long
def zeroColumnAtOnce(ds, colName):
colIndex = ds.getColumnIndex(colName)
colType = ds.getColumnType(colIndex)
ds = system.dataset.filterColumns(ds, [i for i in range(ds.columnCount) if i != colIndex])
ds = system.dataset.addColumn(ds, colIndex, [0] * ds.rowCount, colName, colType)
return ds
def zeroColumnIteratively(ds, colName):
copy = ds
for row in range(ds.rowCount):
copy = system.dataset.setValue(copy, row, colName, 0)
return copy
def generateSample(rows=1000, cols=5):
sampleDataHeaders = ["Column %s" % (col + 1) for col in range(cols)]
sampleData = [[i, Float(i), Double(i), Long(i), str(i)] for i in range(rows)]
return system.dataset.toDataSet(sampleDataHeaders, sampleData)
def time(function, runs, **kwargs):
start = system.date.now()
data = generateSample(**kwargs)
for run in range(runs):
function(data, "Column 3")
end = system.date.now()
elapsed = system.date.millisBetween(start, end)
avg = elapsed / float(runs)
rows = data.rowCount
print "Running '%s' on a dataset with %s rows %s times took %sms; average: %sms" % (function.__name__, rows, runs, elapsed, avg)
time(zeroColumnAtOnce, 10000, rows=100)
time(zeroColumnIteratively, 10000, rows=100)