i'm trying to get familiar with the new Dataset-stuff in Mathematica 10. As it will (hopefully) provide some benefit for me, I have started to convert my app to move from list and list of rules to Associations and Datasets.
Starting point for me is an XML object, which is converted to a Dataset now. I was hoping to reduce the programming code by e.g. applying functions to multiple columns at once.
This is an example Dataset:
testset = Dataset[{<|"Element" -> "A", "a" -> "529251", "b" -> "520358"|>, <|
"Element" -> "B", "a" -> "51"|>, <|"Element" -> "C",
"a" -> "177"|>, <|"Element" -> "L", "a" -> "125"|>, <|
"Element" -> "S", "a" -> "1343"|>}]
This gives:

As the XML sometimes contains integers and reals in scientific form, I'm using
Internal`StringToDouble
to convert the stuff:
fnStr2Real[x_,r_:0]:=If[Head[x]===Missing,r,Internal`StringToDouble[x]]
SetAttributes[fnStr2Real, {Listable}];
testset[fnStr2Real, {"a", "b"}]
(* Trace yields *)
(* Query[fnStr2Real, {"a", "b"}][testset] *)
The issue: there is some kind of rounding in the resulting recordset:

If I apply my function directly to my list or association, everything is fine:
Function[x, fnStr2Real[#[x] & /@ Normal[testset]]] /@ {"a", "b"}
(* {{529251., 51., 177., 125., 1343.}, {520358., 0, 0, 0, 0}} *)
I know that Internal`StringToDouble is an internal function, but I found several posts in this forum using it, and I really like it!
Is there an issue with M10, Dataset and Internal`StringToDouble?
Are there any other robust string coversion functions availabe which can handle integers, reals and reals in scientific form inside a dataset? Thanks!
Answer
I don't yet know where the rounding is coming from but it appears to be occurring during formatting.
Consider:
testset[fnStr2Real, {"a", "b"}] // Normal // Normal
{{"a" -> 529251., "b" -> 520358.}, {"a" -> 51., "b" -> 0},
{"a" -> 177., "b" -> 0}, {"a" -> 125., "b" -> 0}, {"a" -> 1343., "b" -> 0}}
Actually the rounding seems to be a standard part of the formatting of Dataset:
Dataset[<|a -> 123456.|>]

Comments
Post a Comment