TypeError can't put column of type color into dataset

Hello.

I have some tags which contain style configurations for vision status charts. I'm attempting to create a perspective view of these status charts, and tie the colours used to the ones from the status charts (so they only need to be changed in one place).

I run a named query, and then use a script transform to add the column with the colours.

import java.awt.Color
	
styles_dataset = system.dataset.toPyDataSet(
	system.tag.readBlocking(
	["[default]my/tagpath"])[0].value
	)
	
colour_dict = {}
	
for row in styles_dataset :
	colour_dict[row[1]] = row[2] # number code : Color
	
colors_col = [colour_dict[status] for status in value.getColumnAsList(2)]  # read from status code column
	
dataset_w_colors = system.dataset.addColumn(value, colors_col, "color", java.awt.Color)
	
return dataset_w_colors

However, I get the following error (which i can't seem to ctrl-c):

It seems like Color should be allowed, according to Can't use Color Datatype in Dataset tag anymore, error: 'Invalid DataType for Dataset.' - #2 by Kevin.Herron

Is there something I'm missing?

(Also, thinking about it, it's unlikely this method will work anyways, as I am planning to use the DeriveFieldsFromData portion of a perspective xy chart to display the data. So, I'll just manually stringify the colours, I suppose)

Heh, looks like addColumn has its own logic for checking what's allowed.

Classic...

1 Like

I created a bug ticket for this, but given some recent direction from "above" I doubt this qualifies for fixing in 8.1, so I'd find a workaround.

1 Like

Sounds good. I'll probably just stringify the column manually (something like java - Convert a RGB Color Value to a Hexadecimal String - Stack Overflow).

EDIT: "#%02x%02x%02x"%(color.getRed(), color.getGreen(), color.getBlue())

1 Like

Probably the most feasible workaround will be to use the Dataset Builder.

3 Likes

Do you mind if I ask the reason why datasets prohibit certain types? (or more likely, have a limited whitelist)

I'm going to assume it's related to mutability, and wanting to prevent people from accidentally creating hidden bugs.

I think it's mostly because memory tags can contain datasets and we can't serialize arbitrary types when persisting the value.

1 Like

Is there a reason that the check is more complicated that simply seeing "does this implement Serializable"?

Persistence doesn't use Java serialization, and more broadly speaking, Java serialization is the devil and currently being excised from the platform wherever possible.

2 Likes