# Weird Python error with dataset.getValueAt()

**URL:** <https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [October 31, 2019, 5:30pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572 "2019-10-31T17:30:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 31, 2019, 5:30pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/1 "2019-10-31T17:30:29Z")

</div>

I have this little piece of code that ignition keeps throwing an error on. It doesn’t like line 3 for whatever reason but the code works so I am not sure what its issue is. Does someone see something that I don’t see?

Edit:  
I should say that this code takes the first and last values of a chart (this code sits in the propertychange of a chart). Finds the difference and sends that value to a label.

```auto
Dataset = event.source.Data
row = Dataset.getRowCount()-1
end = Dataset.getValueAt(row,1)
start = Dataset.getValueAt(0,1)
change = end - start
event.source.parent.getComponent('Label and Label (1)').Value = change

```

```auto
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
 File "<event:propertyChange>", line 3, in <module>
     at com.inductiveautomation.ignition.client.gateway_interface.OptimizedDataSet.getValueAt(OptimizedDataSet.java:122)

     at com.inductiveautomation.factorypmi.application.binding.util.NonSerializingDataset.getValueAt(NonSerializingDataset.java:66)

     at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)

     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

     at java.lang.reflect.Method.invoke(Unknown Source)

 
 java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 25920
 
     at org.python.core.Py.JavaError(Py.java:495)
     at org.python.core.Py.JavaError(Py.java:488)
     at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:188)
     at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:204)
     at org.python.core.PyObject. __call__ (PyObject.java:422)
     at org.python.core.PyObject. __call__ (PyObject.java:426)
     at org.python.core.PyMethod. __call__ (PyMethod.java:139)
     at org.python.pycode._pyx40.f$0(<event:propertyChange>:6)
     at org.python.pycode._pyx40.call_function(<event:propertyChange>)
     at org.python.core.PyTableCode.call(PyTableCode.java:165)
     at org.python.core.PyCode.call(PyCode.java:18)
     at org.python.core.Py.runCode(Py.java:1275)
     at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)
     at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:180)
     at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.access$000(ActionAdapter.java:40)
     at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter$ActionRunner.run(ActionAdapter.java:286)
     at java.awt.event.InvocationEvent.dispatch(Unknown Source)
     at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
     at java.awt.EventQueue.access$500(Unknown Source)
     at java.awt.EventQueue$3.run(Unknown Source)
     at java.awt.EventQueue$3.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
 Caused by: org.python.core.PyException: Traceback (most recent call last):
 File "<event:propertyChange>", line 3, in <module>
     at com.inductiveautomation.ignition.client.gateway_interface.OptimizedDataSet.getValueAt(OptimizedDataSet.java:122)

     at com.inductiveautomation.factorypmi.application.binding.util.NonSerializingDataset.getValueAt(NonSerializingDataset.java:66)

     at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)

     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

     at java.lang.reflect.Method.invoke(Unknown Source)

 
 java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 25920
 
     ... 30 common frames omitted
 Caused by: java.lang.ArrayIndexOutOfBoundsException: 25920
     at com.inductiveautomation.ignition.client.gateway_interface.OptimizedDataSet.getValueAt(OptimizedDataSet.java:122)
     at com.inductiveautomation.factorypmi.application.binding.util.NonSerializingDataset.getValueAt(NonSerializingDataset.java:66)
     at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:186)
     ... 27 common frames omitted
 

```

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [October 31, 2019, 5:57pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/3 "2019-10-31T17:57:47Z")

</div>

If your doing this as a property change script do you have anything above this? Normally with a property change script you would want to add filters.

When I copy and paste what you have other than the last line and do a “print change” it works as I’d expect it to. That’s what makes me wonder if its related to whatever filters you have set up in your property change script prior to this.

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 31, 2019, 6:21pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/4 "2019-10-31T18:21:15Z")

</div>

What do you mean by filters?

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [October 31, 2019, 6:29pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/5 "2019-10-31T18:29:33Z")

</div>

Multiple properties change anytime you change something on an object. For example if I tie a chart to the history of a tag and use a date range picker to set the time range. Then inside of the propertyChange function of the chart I put

```auto
print event.propertyName

```

When I change the date range, I will get the following in printed to my console:

```auto
propertiesLoading
Data
propertiesLoading

```

When each of these where printed in my console the script ran once. So for that one date change my property change script ran 3 times. Each object is different about what properties it has available to it but each change it likely to make your script run more than once. If you don’t have it filtered using if statements you can get results you don’t want or cause an extra load on your system. Because of this I assumed you would have something prior to the script you had posted.

---

<div class="post-metadata">

**Author:** ![brian.kehn](https://avatars.discourse-cdn.com/v4/letter/b/bbe5ce/32.png) [@brian.kehn](https://forum.inductiveautomation.com/u/brian.kehn)\
**Post date:** [October 31, 2019, 6:33pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/6 "2019-10-31T18:33:56Z")

</div>

I get errors like this all the time, and what I do is just simplify the code and add print statements.This exception makes me think it's just a simple problem with the inputs that .getValueAt() is expecting.

> [@jparsons](#):
>
> java.lang.ArrayIndexOutOfBoundsException:

I would just make a button on a main window, copy and paste the code into it's scripting window. Comment out the code below that line ("Ctrl + /"), and print the value of "row".

```auto
Dataset = event.source.Data
row = Dataset.getRowCount()-1
print "my row value: %s" % row

#end = Dataset.getValueAt(row,1)
#start = Dataset.getValueAt(0,1)
#change = end - start
#event.source.parent.getComponent('Label and Label (1)').Value = change

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 31, 2019, 6:45pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/7 "2019-10-31T18:45:24Z")

</div>

Since you only want this to happen when Data changes, you can add a ‘filter’ to check what property changed:

```python
if event.propertyName == 'Data':
	Dataset = event.source.Data
	row = Dataset.getRowCount()-1
	end = Dataset.getValueAt(row,1)
	start = Dataset.getValueAt(0,1)
	change = end - start
	event.source.parent.getComponent('Label and Label (1)').Value = change

```

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [October 31, 2019, 6:52pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/8 "2019-10-31T18:52:14Z")

</div>

Oh I see what you guys mean by filters now. I was thinking about this the other day but didn’t really put too much thought into it. I will check this and see if it changes anything.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 31, 2019, 7:31pm UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/9 "2019-10-31T19:31:14Z")

</div>

I would agree that a filter is absolutely needed in this case (actually in all cases). It appears that the script is running when the data property is still empty, which would cause getRowCount() to return 0 meaning that line 3 would be trying to access the value at [-1,1]. Resulting in the Index out of bounds exception.

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [November 1, 2019, 11:23am UTC](https://forum.inductiveautomation.com/t/weird-python-error-with-dataset-getvalueat/29572/10 "2019-11-01T11:23:25Z")

</div>

Yes! The filter was what was needed. Thank you all so much! My property change scripts will always have filters from now on!
