2
$\begingroup$

I have a simple Dataset:

segmentMap = Dataset[{ <|"id"->1,  "alignType"->0, "x1"->-3.0, "x2"->3.0, "y1"->3.0, "y2"->3.0, "z1"->0.0, "z2"->0.0,   "State"->0|>,
                       <|"id"->2, "alignType"->1,  "x1"->0.0, " x2"->0.0, "y1"->-3.0, "y2"->3.0, "z1"->0.0, "z2"->0.0,   "State"->0|>,  
                       <|"id"->3, "alignType"->0,  "x1"->-3.0, "x2"->3.0, "y1"->-3.0, "y2"->-3.0, "z1"->0.0, "z2"->0.0, "State"->0|>,
                       <|"id"->4, "alignType"->2,  "x1"->0.0,  "x2"->0.0, "y1"->0.0, " y2"->0.0, "z1"->0.0, "z2"->1.5, "State"->0|>,
                       <|"id"->5, "alignType"->0, "x1"->-3.0, "x2"->3.0, "y1"->3.0, "y2"->3.0, "z1"->1.5, "z2"->1.5,   "State"->0|>,
                       <|"id"->6, "alignType"->1, "x1"->-3.0, "x2"->-3.0, "y1"->-3.0, "y2"->3.0, "z1"->1.5, "z2"->1.5, "State"->0|>,
                       <|"id"->7, "alignType"->1, "x1"->3.0, "x2"->3.0, "y1"->-3.0, "y2"->3.0, "z1"->1.5, "z2"->1.5, "State"->0|>,
                       <|"id"->8, "alignType"->0, "x1"->-3.0, "x2"->3.0, "y1"->-3.0, "y2"->-3.0, "z1"->1.5, "z2"->1.5,   "State"->0|>,
                       <|"id"->9, "alignType"->2, "x1"->-3.0, "x2"->-3.0, "y1"->3.0, "y2"->3.0, "z1"->0.0, "z2"->1.5, "State"->1|>,
                       <|"id"->10, "alignType"->2, "x1"->-3.0, "x2"->-3.0, "y1"->-3.0, "y2"->-3.0, "z1"->0.0, "z2"->1.5, "State"->1|>,
                       <|"id"->11, "alignType"->2, "x1"->3.0, "x2"->3.0, "y1"->3.0, "y2"->3.0, "z1"->0.0, "z2"->1.5, "State"->1|>,
                       <|"id"->12, "alignType"->2, "x1"->3.0, "x2"->3.0, "y1"->-3.0, "y2"->-3.0, "z1"->0.0, "z2"->1.5, "State"->1|>}];

When I use a Select to return rows where State==1, I get two additional columns named " y2" and " x2" with a value of "KeyAbsent".

{
 {"id", "alignType", "x1", "x2", "y1", "y2", "z1", "z2", "State", 
  " y2", " x2"},
 {9, 2, \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"0.\"\>",
      0.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"1.5\"\>",
      1.5,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), 1, Missing["KeyAbsent", " y2"], Missing[
  "KeyAbsent", " x2"]},
 {10, 2, \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"0.\"\>",
      0.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"1.5\"\>",
      1.5,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), 1, Missing["KeyAbsent", " y2"], Missing[
  "KeyAbsent", " x2"]},
 {11, 2, \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"0.\"\>",
      0.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"1.5\"\>",
      1.5,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), 1, Missing["KeyAbsent", " y2"], Missing[
  "KeyAbsent", " x2"]},
 {12, 2, \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"3.\"\>",
      3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"-3.\"\>",
      -3.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"0.\"\>",
      0.,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), \!\(
    TagBox[
     InterpretationBox["\<\"1.5\"\>",
      1.5,
      AutoDelete->True],
     NumberForm[#, 4]& ]\), 1, Missing["KeyAbsent", " y2"], Missing[
  "KeyAbsent", " x2"]}
}

Am I omitting something in my Dataset construction?

$\endgroup$
3
  • $\begingroup$ Without seeing your select its hard to tell - but as far as Dataset is concerned its returning the right result. Look at ID's 2 and 4 - they have "columns" with non-abscent values for Keys x2 and y2. Are you expecting Dataset results to format them selves to less columns without specifying them? Dont forget you have defined the full Dataset as having keys x2 and y2. $\endgroup$ Apr 30 '15 at 16:57
  • $\begingroup$ More importantly you have spaces preceding some of the y2 and x2 keys :D $\endgroup$ Apr 30 '15 at 17:05
  • $\begingroup$ Hi Gordan - the Select statement is segmentMap[Select[#State ==1 &]]. Thanks for the review - did not see the spaces in ID's 2 and 4. $\endgroup$ Apr 30 '15 at 17:20
3
$\begingroup$

Not withstanding the keys with spaces issue.

Dataset doesn't automatically reform itself to drop unneeded columns.

You need this :

segmentMap[Select[#State == 1 &]] // Normal // Dataset

There's probably also a "pure" dataset version without dropping into Normal although I can't think of one right now that doesn't need you to specify the key names.

Or to be specific about the columns when you do a Select :

segmentMap[Select[#State == 1 &], {"id", "alignType", "x1", "x2", "y1", "y2","z1", "z2"}]
$\endgroup$
1
  • $\begingroup$ Hi Gordon - good information - thanks very much! $\endgroup$ Apr 30 '15 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.