# Dataset Column Datatype Inference

**URL:** <https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [February 27, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451 "2024-02-27T17:21:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 27, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451/1 "2024-02-27T17:21:30Z")

</div>

I have a dataset who's data is filled in via a `runScript()` binding.

There's one column that is _usually_ an integer, but there's certainly no reason that it _couldn't_ be a double. It seems like python (thinking it's actually java) wants to assume it's an integer unless I include a decimal point.

So the issue is when the first row in the dataset uses an integer in this column it assumes an integer type. Then, later down in the dataset, java hits an error when it tries to convert the double to an int. It's really annoying to have to go back and add the decimal point to every row entry for this dataset. Is there anything IA could do about this behavior, or is it just a java thing?

---

<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:** [February 27, 2024, 5:26pm UTC](https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451/2 "2024-02-27T17:26:19Z")

</div>

You're skipping over a lot of details, but I'm _guessing_ somewhere in there you're calling `system.dataset.toDataSet` on some Python structure. You're correct; that will rely on 'sniffing' the first row's datatype to determine what Java type to use for the actual dataset column.  
The easiest solution would be to explicitly cast every value in that column (in your script) via the `float()` builtin. Confusingly, Jython's `float` is actually a Java `double`, but c'est la vie.  
The second best solution, if that's not an option for whatever reason, would be to use the [`DatasetBuilder`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.37/com/inductiveautomation/ignition/common/util/DatasetBuilder.html) class to explicitly specify your column names and types, then imperatively add however many rows you need. (If you want a nicer interface than having to import it, consider [Ignition Extensions](https://github.com/IgnitionModuleDevelopmentCommunity/ignition-extensions)).

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [February 27, 2024, 5:28pm UTC](https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451/3 "2024-02-27T17:28:36Z")

</div>

> [@paul-griffith](#):
>
> I'm _guessing_ somewhere in there you're calling `system.dataset.toDataSet` on some Python structure. You're correct; that will rely on 'sniffing' the first row's datatype to determine what Java type to use for the actual dataset column.  
> The easiest solution would be to explicitly cast every value in that column (in your script) via the `float()` builtin. Confusingly, Jython's `float` is actually a Java `double`, but c'est la vie.

Correct assumption.

I opted for the annoying, but not too bad, solution of just adding ".0" to every int for those columns. _Technically_ I only needed it for the first row of the dataset, but I want it on all rows just for consistency.

---

<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:** [February 27, 2024, 5:28pm UTC](https://forum.inductiveautomation.com/t/dataset-column-datatype-inference/86451/4 "2024-02-27T17:28:39Z")

</div>

You could also use the Integration Toolkit module's [unionAll()](https://www.automation-pros.com/toolkit/doc/datasets.html#unionall) expression function, which uses the DatasetBuilder, and accepts the string shortcuts for data types.
