# "Cannot convert row x column y to type java.lang.Long"

**URL:** <https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175>\
**Category:** Ignition\
**Created:** [April 23, 2020, 8:57pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175 "2020-04-23T20:57:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [April 23, 2020, 8:57pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/1 "2020-04-23T20:57:19Z")

</div>

So, I’ve seen threads similar to this, but this one I really do think is some kind of bug.

I have a dataset with rows/columns that, when printed via a logger given by `system.util.getLogger`, returns something like:

`[[5L, 3.6], [0L, 0L] ]`

Or something similar, this is just for illustrative purposes.

So when I try to do `system.dataset.toDataSet` on this (with a header list provided, of course) it fails with

`Unable to convert row x, column y to type class java.lang.Long`

I can clearly tell it’s because the float/integers aren’t meshing properly.

However, no matter what I do, I cannot get the script to treat the integers in there as floats. Wrapping them in `float()` doesn’t work, wrapping them in `java.lang.Float()` doesn’t work, adding `0.0` doesn’t work, multiplying by `1.0` doesn’t work. Nothing.

The only option that has worked has been adding a small value to each number in order to **force** it to be a float, in my case `0.0001`. This is, quite obviously, not ideal. And given how I cannot seem to get this to work normally, at all, no matter what I try, I feel like it has to be a bug.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [April 23, 2020, 9:05pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/2 "2020-04-23T21:05:07Z")

</div>

What version are you on?

Testing this in the script console works for me:

```auto
old = [[5L, 3.6], [0L, 0L] ]

new = [[float(subitem) for subitem in item] for item in old]

print system.dataset.toDataSet(['Col1', 'Col2'], new)
		

```

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [April 23, 2020, 9:06pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/3 "2020-04-23T21:06:52Z")

</div>

That works for me too in the script console.

I’m passing data in from a perspective component’s `data` property, since apparently that seems to matter?

This is taking place within a function that converts a list of dicts to a dataset, here’s that function.

```auto
def list_to_ds(in_list):
	"""
	Converts a list of dicts to an Ignition DataSet.
	
	This assumes that the first item in the list is a dict that contains all of the keys that will also be present in all other items.
	"""
	headers = in_list[0].keys()
	
	output_list = []
	
	for row in in_list:
		new_row = [row[key] for key in headers ]
		output_list.append(new_row)
	
	logger = system.util.getLogger("test")
	logger.info(str(output_list))
	
	ds = system.dataset.toDataSet(headers, output_list)
	
	return ds
	

```

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [April 23, 2020, 9:11pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/4 "2020-04-23T21:11:10Z")

</div>

Whelp, I finally got it. I thought I had tried this earlier with a slightly different method, but now it worked.

````auto
def list_to_ds(in_list):
	"""
	Converts a list of dicts to an Ignition DataSet.
	
	This assumes that the first item in the list is a dict that contains all of the keys that will also be present in all other items.
	"""
	headers = in_list[0].keys()
	
	output_list = []
	
	for row in in_list:
		new_row = [row[key] for key in headers ]
		converted_row = []
		
		for item in new_row:
			try:
				item = float(item)
			except:
				pass
				
			converted_row.append(item)
		
		output_list.append(converted_row)
		
	
	logger = system.util.getLogger("test")
	logger.info(str(output_list))
	
	ds = system.dataset.toDataSet(headers, output_list)
	
	return ds
	```
````

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [April 23, 2020, 9:15pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/5 "2020-04-23T21:15:28Z")

</div>

interesting! 😮 what input was causing it to fail?

Happy you got it though 😃

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 23, 2020, 9:38pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/6 "2020-04-23T21:38:32Z")

</div>

You could also use a [`com.inductiveautomation.ignition.common.util.DatasetBuilder`](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/com/inductiveautomation/ignition/common/util/DatasetBuilder.html) to construct the dataset imperatively, with fixed types, rather than relying on the automatic coercion in `system.dataset.toDataset`.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [April 23, 2020, 10:01pm UTC](https://forum.inductiveautomation.com/t/cannot-convert-row-x-column-y-to-type-java-lang-long/34175/7 "2020-04-23T22:01:57Z")

</div>

> [@paul-griffith](#):
>
> [`com.inductiveautomation.ignition.common.util.DatasetBuilder`](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/com/inductiveautomation/ignition/common/util/DatasetBuilder.html)

I wish I knew this existed like 2 years ago! I have code where i manually go through and try to cast every element in a list of lists to a float before calling system.dataset.toDataSet and if it fails that i pop elements from the end of the list until it passes the toDataSet call -\_-
