I have a basic function that populates a Dataset according to user specified parameters.

PopulateMap[eMapId_, eModule_, volBounds_, xInit_, yInit_, zInit_, \[CapitalDelta]x_, \[CapitalDelta]y_, \[CapitalDelta]z_] := 
Module[{eMap, segmentCount, segmentIndex, xPos, yPos, zPos},


      eMap = Dataset[{<|"MapId"->eMapId,
                        "x1"->0, "y1"->0, "z1"->0,
                        "x2"->0, "y2"->0, "z2"->0,

    segmentCount = Length[eModule];

    (* If passed eModule contains no segments *)    
    If[ segmentCount == 0, 

      xPos = xInit;
    yPos = yInit;
    zPos = zInit;

    While[ xPos < volBounds[1]["x2"],

        (* Add segments around {xPos, yPos, zPos} *)
        For[i=1, i<=segmentCount, i++,

            AppendTo[ eMap, <|"MapId"->eMapId,
                              "ModuleId"-> eModule[i]["ModuleId"], 

        xPos += \[CapitalDelta]x;
        yPos += \[CapitalDelta]y;
        zPos += \[CapitalDelta]z;



If I call PopulateMap with an integer for xInit (for example: -197):

eMap = PopulateMap[1, electrodeModule02, volumeBounds, -197, 0, 0, 20, 0, 0]

The Dataset is populated without problem.

If I set xInit to -197.5:

eMap = PopulateMap[1, electrodeModule02, volumeBounds, -197.5, 0, 0, 20, 0, 0]

The following error occurs:

Failure[Append, <|"MessageTemplate" :> Dataset::invalid, 
  "MessageParameters" -> <|"Head" -> Append, 
    "Arguments" -> {TypeSystem`Vector[
        TypeSystem`Atom[Integer], 11], 1]

Taking a queue from SQL-type languages I have used in the past, I made the following change to the first call to Dataset (changed the initial values for x1, y1, z1, x2, y2, z2 from 0 to 0.0:

          eMap = Dataset[{<|"MapId"->eMapId,
                        "x1"->0.0, "y1"->0.0, "z1"->0.0,
                        "x2"->0.0, "y2"->0.0, "z2"->0.0,

After this change, the Dataset is generated without error.

Is there a way to formally define the columns and column types in a Dataset? For example, if I wanted to store table definitions in an external file or database and instantiate the Datasets from the external definitions?

  • $\begingroup$ There seems to be a problem in appending data to a dataset, workaround are on some articles here. Problem is described in mathematica.stackexchange.com/questions/68979/… $\endgroup$
    – mgamer
    Jan 18, 2015 at 18:46
  • $\begingroup$ Could you please make this a self-contained example by defining all of the symbols used (e.g. electrodeModule02 and volumeBounds). The type system uses heuristics heavily and its behaviour is very sensitive to the exact data. Also, please mention which version you are using -- the heuristics have changed radically between 10.0.0, 10.0.1 and 10.0.2. $\endgroup$
    – WReach
    Jan 18, 2015 at 18:56
  • $\begingroup$ See Dataset with no members for ways to create an empty yet typed dataset. $\endgroup$
    – WReach
    Jan 18, 2015 at 19:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.