CSV Export: FieldType.other objects will be stringified (#113854)

This commit is contained in:
Victor Marin
2025-11-13 15:11:10 -05:00
committed by GitHub
parent 23c192f330
commit 09a7a0c94f
2 changed files with 25 additions and 1 deletions
@@ -181,6 +181,26 @@ describe('DataFrame to CSV', () => {
`);
});
it('should handle field type other', () => {
const dataFrame = new MutableDataFrame({
fields: [
{ name: 'Time', values: [1589455688623, 1589455692345] },
{
name: 'Value',
type: FieldType.other,
values: [{ text: 'value1' }, { text: 'value2' }],
},
],
});
const csv = toCSV([dataFrame]);
expect(csv).toMatchInlineSnapshot(`
""Time","Value"
1589455688623,"{""text"":""value1""}"
1589455692345,"{""text"":""value2""}""
`);
});
it('should handle null values', () => {
const dataFrame = new MutableDataFrame({
fields: [
+5 -1
View File
@@ -1,5 +1,5 @@
// Libraries
import { defaults } from 'lodash';
import { defaults, isObject } from 'lodash';
import Papa, { ParseConfig, Parser, ParseResult } from 'papaparse';
// Types
@@ -317,6 +317,10 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string {
v = v.value;
}
if (fields[j].type === FieldType.other && isObject(v)) {
v = JSON.stringify(v);
}
csv += writers[j](v);
}
}