# Ignition reporting Script: PyFloat cannot be cast to org.python.core.PySequence

**URL:** <https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173>\
**Category:** Ignition\
**Created:** [April 29, 2021, 6:50pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173 "2021-04-29T18:50:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmiessner](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dmiessner](https://forum.inductiveautomation.com/u/dmiessner)\
**Post date:** [April 29, 2021, 6:50pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/1 "2021-04-29T18:50:52Z")

</div>

Hello everyone. As you can see from the title I’m having an issue with being unable to cast my data as I attempt to create a new dataset from some data that I modify from an existing dataset.

Below is my code, it’s all fairly shortly.

```auto
data_dump = data['part_count'].getCoreResults()
	
rows = data_dump.rowCount
		
adjusted_header = ['total', 'late', 'on_time']
adjusted_data = [0, 0, 0]	
for row in range(rows):
	id_c = data_dump.getValueAt(row, 'id_count')
	total = data_dump.getValueAt(row, 'total')
	late = data_dump.getValueAt(row, 'late')
	on_time = data_dump.getValueAt(row, 'on_time')
	if id_c != 1:
		adjusted_data[0] += total / id_c
		adjusted_data[1] += late / id_c
		adjusted_data[2] += on_time / id_c
	else:
		adjusted_data[0] += total
		adjusted_data[1] += late
		adjusted_data[2] += on_time
		
		
adjusted_dataset = system.dataset.toDataSet(adjusted_header, adjusted_data)
	data['Accurate Counts'] = adjusted_dataset

```

and my error is the following:

```auto
WARN: Error invoking script.Traceback (most recent call last):
  File "<function:updateData>", line 28, in updateData
	at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:317)

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

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

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

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

java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyFloat cannot be cast to org.python.core.PySequence

```

Any help or insight at all would be greatly appreciated. I had assumed that scripting would lead to some easier data modification than attempting to utilize an SQL query to do it, but this is not an error I ever expected to run into.

Thank you!

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [April 29, 2021, 7:26pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/2 "2021-04-29T19:26:13Z")

</div>

I’m not sure why you’re getting that error, but your definitely building the dataset incorrectly. You would need to do something like this:

```auto
data_dump = data['part_count'].getCoreResults()
	
rows = data_dump.rowCount
		
adjusted_header = ['total', 'late', 'on_time']
adjusted_data = []	
for row in range(rows):
	newRow = []
	id_c = data_dump.getValueAt(row, 'id_count')
	total = data_dump.getValueAt(row, 'total')
	late = data_dump.getValueAt(row, 'late')
	on_time = data_dump.getValueAt(row, 'on_time')
	if id_c != 1:
		newRow.append(total / id_c)
		newRow.append(late / id_c)
		newRow.append(on_time / id_c)
	else:
		newRow.append(total)
		newRow.append(late)
		newRow.append(on_time)
	adjusted_data.append(newRow)
		
		
adjusted_dataset = system.dataset.toDataSet(adjusted_header, adjusted_data)
	data['Accurate Counts'] = adjusted_dataset

```

---

<div class="post-metadata">

**Author:** ![dmiessner](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dmiessner](https://forum.inductiveautomation.com/u/dmiessner)\
**Post date:** [April 29, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/3 "2021-04-29T19:29:14Z")

</div>

Hello Duffanator,

That same method for building a dataset that you recommended to me is something I’ve already done and am doing in other parts of my program, the only difference here is that my goal is it to cut the original dataset, which may have multiple rows, which it should not, down to 1 row that has the totals for all the rows together.

I’m sure there is more manipulation I can do to get it down to that one row that I’m aiming for, but I’ll try this adjustment first to see if the bug goes away in general.

Thank you!

---

<div class="post-metadata">

**Author:** ![dmiessner](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dmiessner](https://forum.inductiveautomation.com/u/dmiessner)\
**Post date:** [April 29, 2021, 8:16pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/4 "2021-04-29T20:16:12Z")

</div>

I figured out the issue. The problem was with this line:

> [@dmiessner](#):
>
> `adjusted_data = [0, 0, 0]	`

It didn't want to cast those from floats/ints to a sequence.

I also determined that an easier way to do this than what I was doing before was to just do total / id\_count inside of the report itself, instead of attempting to do it through a dataset. It worked more easily and was less code intensive.

The problem with this, though, is that it doesn't accurately display the totals for all of the columns, now, only for each individual part in my table. Which brings me back to scripting probably being the easiest way to handle this solution cleanly and finally, instead of a makeshift solution that only works in a given environment.

---

<div class="post-metadata">

**Author:** ![dmiessner](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dmiessner](https://forum.inductiveautomation.com/u/dmiessner)\
**Post date:** [April 30, 2021, 1:19pm UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/5 "2021-04-30T13:19:42Z")

</div>

Sometimes coming into a project fresh again in the morning is all it takes to solve a problem.

This is the final working version of what I was attempting to do. Neater code and working through stuff in multiple steps fixed the issue.

```auto
	counts = data['part_count'].getCoreResults()
	rows = counts.rowCount
	
	header = ['total', 'late', 'on_time']
	
	fixed = []
	for row in range(rows):
		temp = []
	
		id_count = counts.getValueAt(row, 'id_count')
		late_count = counts.getValueAt(row, 'late')
		total_count = counts.getValueAt(row, 'total')
		on_time_count = counts.getValueAt(row, 'on_time')
		
		fixed_late = late_count / id_count
		fixed_total = total_count / id_count
		fixed_on_time = on_time_count / id_count
		
		temp.append(fixed_total)
		temp.append(fixed_late)
		temp.append(fixed_on_time)
		
		fixed.append(temp)
		
	
	fixed_dataset = system.dataset.toDataSet(header, fixed)
	
	data['counts'] = fixed_dataset	

```

Simply divides the counts by the id\_count. id is something that can be repeated if one of our employees clocks into the same part multiple times for this report, but if they only clocked in 1 time, quantity divided by 1 is still the quantity, while every other case will give an accurate quantity count.

The following query is how we pull the counts to start with.

```auto
select
sum(quantity) as total,

sum(
	case 
		when date_scheduled < completion_date
			then quantity
		else 0
	end) as late,
		
sum(
	case
		when date_scheduled >= completion_date
			then quantity
		else 0
	end) as on_time,
	
count(id) as id_count
	
from masterfabparts2 m, partsworkedon p where completion_date >= ? and completion_date <= ? and m.id = p.part_id_mf and p.username = ?
group by id

```

---

<div class="post-metadata">

**Author:** ![Koen](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@Koen](https://forum.inductiveautomation.com/u/Koen)\
**Post date:** [December 28, 2024, 8:02am UTC](https://forum.inductiveautomation.com/t/ignition-reporting-script-pyfloat-cannot-be-cast-to-org-python-core-pysequence/46173/6 "2024-12-28T08:02:17Z")

</div>

I had the same problem, for me I just had to put the 'adjusted\_data' in square brackets.

Translated to your original script, like this:  
`system.dataset.toDataSet(adjusted_header, [adjusted_data])`
