TypeError: 'reflectedfunction' object is unsubscriptable

Hello,

Perhaps someone can help me find the error in my code here. I’m getting the message “TypeError: ‘reflectedfunction’ object is unsubscriptable”.

#Variables##############

DataSetTag = '[default]Folder/MinMaxAvgDev' #this is the dataset tag where the aggregated data from a previous script will land
AvgCol = 3 #column number in dataset where avg value is located
DevCol = 4 #column number in dataset where dev value is located

Usls = [																			# Tag paths for USL values go here	
	'[default]Folder/HeightUSL',
	'[default]Folder/WidthUSL',
	]
	
Lsls = [																			# Tag paths for LSL values go here	
	'[default]Folder/HeightLSL',
	'[default]Folder/WidthLSL',
	]
	
Cpks = [																			# Tag paths for Cpk values go here
	'[default]Folder/HeightCpk',
	'[default]Folder/WidthCpk',
	]

#Definition#############

def calculateCPK(DataSetTag, Usl, Lsl, DataRow, AvgCol, DevCol, CpkTag):
	import system
	pyData = system.dataset.toPyDataSet((system.tag.read(DataSetTag).value)) # First convert the dataset to a PyDataset.
 	#print pyData[1][2] The data can then be accessed using two brackets at the end with row and column indexes.
	# Cpk = min(USL - μ, μ - LSL) / (3σ) where USL and LSL are the upper and lower specification limits, μ is the process mean, and σ is the process standard deviation.
	if pyData[DataRow][DevCol] != 0: #This part of the if statement is being executed
		Cpk=(system.math.min[((system.tag.read(Usl).value)-pyData[DataRow][AvgCol]),(pyData[DataRow][AvgCol]-(system.tag.read(Lsl).value))])/(3*pyData[DataRow][DevCol]) #This line of code is generating the error
		#print Cpk
	else: # this else statement is not being executed
		Cpk=0
		#print "No Cpk"
	system.tag.write(CpkTag, Cpk)

#Program############

for x in range((system.tag.read(DataSetTag).value.getRowCount())):
	calculateCPK(DataSetTag, Usls[x], Lsls[x], x, AvgCol, DevCol, Cpks[x]) #invoke calculate Cpk function once per row

Thanks

That is not valid syntax for invoking the min function. Wrong bracket type.

Excellent, great catch, thanks for your help! Here is the corrected line:

Cpk=(system.math.min([((system.tag.read(Usl).value)-pyData[DataRow][AvgCol]),(pyData[DataRow][AvgCol]-(system.tag.read(Lsl).value))])/(3*pyData[DataRow][DevCol]))