# Report Script PySequence error

**URL:** <https://forum.inductiveautomation.com/t/report-script-pysequence-error/21447>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 17, 2018, 1:38pm UTC](https://forum.inductiveautomation.com/t/report-script-pysequence-error/21447 "2018-12-17T13:38:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engodel](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@Engodel](https://forum.inductiveautomation.com/u/Engodel)\
**Post date:** [December 17, 2018, 1:38pm UTC](https://forum.inductiveautomation.com/t/report-script-pysequence-error/21447/1 "2018-12-17T13:38:59Z")

</div>

Hello,

I was wondering if you could help me with the below Script  
\> Header = ['Time','Fault','Reason']

> statusdataset =   
> rawDataset = data['Bay 1'].getCoreResults()  
> i=0
> 
> for row in range(4):  
> i=i+1  
> Chill = "chiller status " + str(i)  
> chiller = rawDataset.getValueAt(row,Chill)  
> time = rawDataset.getValueAt(row,'t\_stamp')  
> reason = "Chiller Faulted"  
> rowLen= rawDataset.rowCount  
> for row in range(rowLen):   
> if chiller ==3:  
> statusdataset.append([time,chiller,reason])  
> statusdataset= system.dataset.toDataSet(Header,statusdataset)  
> data['Chiller' + str(i)] = statusdataset

I get an error that states:  
TypeError: toDataSet(): 2nd arg can't be coerced to org.python.core.PySequence

However if I move the below lines to the first for loop, i no longer get the error, But I only get the data from the last iteration of the for loop  
statusdataset= system.dataset.toDataSet(Header,statusdataset)

> ```
> data['Chiller' + str(i)] = statusdataset
> 
> ```

So I have 4 history tags in a Tag Historian Query , I than have the above script to try and only take the values from the tag history if it is = to 3 on all 4 history tags.

I have tried the script for just one tag without the for loop and it gave me all of the data from the 4 tags in one dataset, but I would like to filter them out into 4 different datatypes. For ref, the code that kinda worked is below

> Header = ['Time','Fault','Reason']  
> statusdataset =   
> rawDataset = data['Bay 1'].getCoreResults()
> 
> for row in range(rawDataset.rowCount):  
> chiller = rawDataset.getValueAt(row,'Chiller Status')  
> time = rawDataset.getValueAt(row,'t\_stamp')  
> reason = "Chiller Faulted"  
> if chiller ==3:  
> statusdataset.append([time,chiller,reason])
> 
> statusdataset= system.dataset.toDataSet(Header,statusdataset)  
> data['newChiller'] = statusdataset

---

<div class="post-metadata">

**Author:** ![Stevenson.Yuan](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@Stevenson.Yuan](https://forum.inductiveautomation.com/u/Stevenson.Yuan)\
**Post date:** [December 17, 2018, 3:37pm UTC](https://forum.inductiveautomation.com/t/report-script-pysequence-error/21447/2 "2018-12-17T15:37:26Z")

</div>

> [@Engodel](#):
>
> statusdataset

I think your statusdataset is throwing your logic off.  
Ln1: statusdataset initialized as list  
Ln14: statusdataset gets a list appended  
Ln15: statusdataset turned into a dataset obj

On second pass Ln14 should fail as it's no longer a list object

```auto
	
rawDataset = data['Bay 1'].getCoreResults()
i=0

for row in range(4):
		i=i+1
        statusdataset = [] #this needs to be reinitialized on each iteration
		Chill = "chiller status " + str(i)
		chiller = rawDataset.getValueAt(row,Chill)
		time = rawDataset.getValueAt(row,'t_stamp')
		reason = "Chiller Faulted"
		rowLen= rawDataset.rowCount
		for row in range(rowLen):	
				if chiller ==3:
						statusdataset.append([time,chiller,reason])
		statusdataset= system.dataset.toDataSet(Header,statusdataset)
		data['Chiller' + str(i)] = statusdataset

```

---

<div class="post-metadata">

**Author:** ![Engodel](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@Engodel](https://forum.inductiveautomation.com/u/Engodel)\
**Post date:** [December 17, 2018, 4:05pm UTC](https://forum.inductiveautomation.com/t/report-script-pysequence-error/21447/3 "2018-12-17T16:05:37Z")

</div>

Worked like a charm, Thank you
