Type coercion / ignored format on export? #355
Unanswered
rjbudzynski
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The output methods appear to be working fine: aq.table({ foo: ["02", "04", "12", "22"] }).toCSV()
// foo
// 02
// 04
// 12
// 22
aq.table({ foo: ["02", "04", "12", "22"] }).toJSON()
// {"schema":{"fields":[{"name":"foo"}]},"data":{"foo":["02","04","12","22"]}} I'm guessing the problem is that the values are being parsed as strings upon load. So I'd look at the data loading and possibly make changes there. Below is an example that adds options to the CSV parser to avoid coercing digit strings. // standard auto-type parsing results in number coercion
aq.fromCSV(`foo\n02\n04\n12\n22`).toJSON()
// {"schema":{"fields":[{"name":"foo"}]},"data":{"foo":[2,4,12,22]}}
// using custom identify function parser for column foo
aq.fromCSV(`foo\n02\n04\n12\n22`, { parse: { foo: x => x } }).toJSON()
// {"schema":{"fields":[{"name":"foo"}]},"data":{"foo":["02","04","12","22"]}} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my table I have a column where the values are strings of two digits, like "02", "04", ..."12", "22" and so on.
If I call
table.toJSON()
values in this column are coerced to numbers. This is most certainly not what I want, and it's very undesirable when dealing with codes which are strings of digits which might have leading zeroes.I even tried
table.toJSON({ format: { WOJ: d => String(d).padStart(2,"0") }})
but the format seems to be ignored.A similar issue arises when exporting to Arrow, specifying the arrow type of the column as
Utf8
has no effect.Beta Was this translation helpful? Give feedback.
All reactions