# Python typing issues

**URL:** <https://forum.inductiveautomation.com/t/python-typing-issues/64535>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [September 27, 2022, 2:50pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535 "2022-09-27T14:50:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_McPherson](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@Chris\_McPherson](https://forum.inductiveautomation.com/u/Chris_McPherson)\
**Post date:** [September 27, 2022, 2:50pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/1 "2022-09-27T14:50:16Z")

</div>

I have been running across strange behavior with data types when passing or returning from functions. In the same script I have run across two issues since the update to 8.1.19

> **Summary**
>
> 1. When passing a pyDataSet to a function it becomes a basic dataset (which breaks when indexing)
> 
> ```auto
> PsetPDS = system.dataset.toPyDataSet(PsetDS)
> 
> system.perspective.print(psetManagement.executeRule(PsetDS))
> 
> ```
> 
> gives the result:  
> class com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset
> 
> def executeRule(rule):  
> #broken for some reason won’t access the dataset like it should  
> #changed to Basic streaming for no reason  
> #added return type just for testing type  
> return type(rule)  
> #This is original code that should run but breaks due to elements not being indexable  
> if rule[0][“operationType”] == 0:  
> psetManagement.deletePADSA(rule)
> 
> ```auto
> 
> ```

1. When using system.db.runNamedQuery, the return type is dependent on results.

```auto
eolIdx = system.db.runNamedQuery("getSnEol",{"serial":serial})

```

gives result of long if the query returns a row of data or a basic dataset if the serial number isn’t found

It seems like Jython is interpreting the results in a way that leads to unexpected behaviors, is there a way to enforce datatypes across functions?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 27, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/2 "2022-09-27T15:05:37Z")

</div>

```auto
def executeRule(rule):
	#broken for some reason won't access the dataset like it should
	#changed to Basic streaming for no reason
	return type(rule)
	#This code should run but breaks due to elements not being indexable
	if rule[0]["operationType"] == 0:
		psetManagement.deletePADSA(rule)

```

This function looks weird. You’re comment that that part should run isn’t true since you have a `return type(rule)` above it (which will also never equal `True`) but perhaps that’s for testing.

The only thing I’ve noticed that is somewhat annoying about the datasets from query functions is that `system.db.runNamedQuery` do return a `BasicDataset` while the `system.db.runQuery/runPrepQuery` return PyDataSet.

However I don’t see how or why a function call would change the type. Can you prove this ? What happens if you modify your code like

```auto
PsetPDS = system.dataset.toPyDataSet(PsetDS)
print type(PsetPDS)
psetManagement.executeRule(PSetDS)

def executeRule(rule):
	#broken for some reason won't access the dataset like it should
	#changed to Basic streaming for no reason
	print type(rule)

```

In designer for instance running this doesn’t show any implicit conversion of the dataset types

```auto
testDS = system.dataset.toDataSet([],[[]])
testPyDS = system.dataset.toPyDataSet(testDS)

print type(testDS)
print type(testPyDS)

def func(ds):
	print type(ds)

func(testDS)
func(testPyDS)

```

```auto
<type 'com.inductiveautomation.ignition.common.BasicDataset'>
<type 'com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet'>
<type 'com.inductiveautomation.ignition.common.BasicDataset'>
<type 'com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet'>

```

This is not something I’ve ever run into.

---

<div class="post-metadata">

**Author:** ![Chris\_McPherson](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@Chris\_McPherson](https://forum.inductiveautomation.com/u/Chris_McPherson)\
**Post date:** [September 27, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/3 "2022-09-27T15:09:52Z")

</div>

Sorry the function is a little weird since the formatting ate it. There are two separate bits of code and the return statement was there to try and figure out what was going wrong. The missing line is

```auto
system.perspective.print(psetManagement.executeRule(PsetDS))

```

I made some edits to the original post

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 27, 2022, 3:15pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/4 "2022-09-27T15:15:41Z")

</div>

_Maybe_ it’s different since perspective is running on the gateway scope but I find that a bit hard to believe, I don’t know though, but I have just never run into types changing on me by themselves with Ignition.

Obviously at this point `PsetPDS = system.dataset.toPyDataSet(PsetDS)` its a PyDataSet, but you’re saying there is no other script in between and when its inside executeRule the type is BasicDataset? Can you show the print statement results of showing right after converting to the pydataset and the print statement inside the function? The only thing I can think is that you are doing some data manipulation in between that accepts a pydataset or a basicdataset as a argument that returns a basicdataset always.

---

<div class="post-metadata">

**Author:** ![Chris\_McPherson](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@Chris\_McPherson](https://forum.inductiveautomation.com/u/Chris_McPherson)\
**Post date:** [September 27, 2022, 3:19pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/5 "2022-09-27T15:19:28Z")

</div>

> [@bkarabinchak.psi](#):
>
> Can you show the print statement results of showing right after converting to the pydataset and the print statement inside the function?

The function is in the script library and is being called on a transform. The exact code snippet is written like this that is giving that output:

```python
if PsetDS.getRowCount() > 0:
		PsetPDS = system.dataset.toPyDataSet(PsetDS)
		system.perspective.print(psetManagement.printPyDataSet(PsetPDS))
		system.perspective.print(PsetPDS[0]["operationType"])
		system.perspective.print(psetManagement.executeRule(PsetDS))

```

truncated version of the function that just gives the return type (with my comments):

```python
def executeRule(rule):
	#system.perspective.print(rule)
	#broken for some reason won't access the dataset like it should
	#changed to streaming for no reason
	return type(rule)

```

There is no other code executed on the PsetDS data at this point.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 27, 2022, 3:23pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/6 "2022-09-27T15:23:00Z")

</div>

> [@Chris\_McPherson](#):
>
> ```auto
> PsetPDS = system.dataset.toPyDataSet(PsetDS)
> 
> system.perspective.print(psetManagement.executeRule(PsetDS))
> 
> ```

You're passing the original dataset to `executeRule`, not the new PyDataSet.

---

<div class="post-metadata">

**Author:** ![Chris\_McPherson](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@Chris\_McPherson](https://forum.inductiveautomation.com/u/Chris_McPherson)\
**Post date:** [September 27, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/7 "2022-09-27T15:27:45Z")

</div>

Wow, right.  
OK, I feel dumb about missing that. I am going to leave up part 2 because that is still unusual.  
Thanks for your help though.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 27, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/8 "2022-09-27T15:29:04Z")

</div>

You should know that somewhere in v8.1, the `PyDataset` class was updated to implement the [Dataset](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/ignition/common/Dataset.html) Interface, making it possible to assign a PyDataset directly into any property that accepts Datasets.

This might have been a mistake. Historically, almost every dataset encountered in Vision or in the Designer was a BasicDataset or one of its subclasses. In the Gateway, a `BasicStreamingDataset` was the other common implementation. The PyDataset implementation of Dataset may break long-standing assumptions in various places.

IMNSHO, the PyDataset type should be retired in favor of a universal Jython proxy for the Dataset interface, similar to the PyComponentWrapper proxy for Vision components. Such a proxy can offer the right methods for python iteration and dictionary emulation for all Dataset implementations. Would be more performant, too, I suspect.

For v8.3, please? If not sooner.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 27, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/python-typing-issues/64535/9 "2022-09-27T15:29:35Z")

</div>

I read your code and I also missed it lol. `PsetDS` and `PsetPDS` are very close in naming.
