Issue with Dataset export to CSV, including float

Hi,

I'm in trouble in exporting (trough system.dataset.toCSV and forExport=True) a simple Power table dataset [2R x 3C] , if it is including a "float". The export seems corrupted, having "#ROWS","3" (instead of 2, as I see in property) and no "#Types" (hereby included the CSV). The data
test2.csv (93 Bytes)
are aggregated by Col (!) and not by Row, as should be. If I remove the 3rd column (the Float) the CSV is OK. Anyone can help about? Thanks.

You'll probably need to share the code as well as the source data object

The source here:

The referenced Power Table has a simple dataset with 3Columns: 1 Str, 1 Int, 1 Float,
The ouput (CSV) is in the previous post.

If I remove the 3rd column (the float) all is working

Have you tried using system.dataset.exportCSV instead? The forExport flag seems to be in order to make a string that matches the system.dataset.fromCSV, rather than a "raw" CSV string.

system.dataset.exportCSV does not export the #TYPES and others. As per the manual.
The system.dataset.toCSV exports the the format that is fully compatible with import, as I need, and as per the manual. If it works with str, int, etc. the same should be with float without "tranposing" Rows and Cols

I'm very confused, your file test2.csv

"#NAMES"
"Descr","INT1","FL1"
"#TYPES"
"str","I","F"
"#ROWS","2"
"A","1","1.1"
"B","2","2.2"

Does show "#ROWS", "2". Is there another corrupted file?

This is the cause of the problem:
image

See the .data on the end of that? The data property of the power table is being retrieved instead of the power table component itself.

Then, in the next line, an attempt is made to get the data property from the resultant dataset because the assumption is that this is actually the power table itself:
image

Either remove the .data from the component variable assignment, or simply retrieve the dataset instead, and use it in the toCSV call.

Example:

# Get the dataset from the power table's data property
dataset = event.source.parent.getComponent('Power Table').data

# Convert the dataset to a csv file
csv = system.dataset.toCSV(dataset, forExport = True)

# Have the user pick a file path
filePath = system.file.saveFile('myExport.csv', 'csv', 'Comma Setperated Values')

# If a filepath has been returned, write the csv accordingly
if filePath:
	system.file.writeFile(filePath, csv)
3 Likes

Thanks Justine, you're perfecly right. My fault. The float is not involved at all.

Many thanks!!