Bug introduced in 11.0.0 and persisting through 11.0.1 or later

In 10.4.1 and previous versions then using GroupBy in a Dataset Query the order that the rows appeared in the ungrouped dataset matched those in the grouped dataset. However, in 11.0.1 the order changes in an unintuitive manner. This is terrible for me as I produce structured reports from Datasets (using nested KeyValueMaps and the like) where the order the records important. Now all of these reports have jumbled grids and tables as a result.

Dataset[AssociationThread[{"A", "B", "C", "D", "E"}, #] & /@
    {"cat", "dog", 1, 2, 3},
    {"cat", "dog", 4, 5, 6},
    {"cat", "mouse", 1, 2, 3},
    {"cat", "mouse", 4, 5, 6},
    {"bird", "rat", 1, 2, 3},
    {"bird", "rat", 4, 5, 6},
    {"bird", "worm", 1, 2, 3},
    {"bird", "worm", 4, 5, 6},
    {"horse", "goat", 1, 2, 3},
    {"horse", "goat", 4, 5, 6},
    {"horse", "pig", 1, 2, 3},
    {"horse", "pig", 4, 5, 6}
    }][GroupBy[{#"A" &, #"B" &}]]

In 10.4.1 and previous versions

Order is preserved; cat, bird, horse.

Mathematica graphics

In 11.0.1

Order is changed to horse, cat, bird. The changing order has no immediate structure to it in the real data although here it may look as if it is reverse alphabetical. The real data has longer strings for groups and subgroups with many more groups and subgroups.

Mathematica graphics

This is not related to the new formatting of Datasets in 11.0.1 because if I set Dataset`$UseNewDatasetFormatting = False I get the pre-11 formatting but the order is still broken.

I feel this is a bug. Thoughts? Version 11.0.1 on Win 7 Ent SP1

Update Confirmed bug CASE:3736993

  • $\begingroup$ Is Dataset explicitly ordered? I believe in other languages similar structures typically are not. $\endgroup$ – user6014 Oct 12 '16 at 15:11
  • 2
    $\begingroup$ @user6014 In Mathematica things tend to stay as entered. Well, that has been my experience in the parts of it that I use. $\endgroup$ – Edmund Oct 12 '16 at 15:19
  • $\begingroup$ I agree, but if something isn't explicitly "ordered" than it isn't unreasonable or incorrect for it to rearrange itself. It's not ideal that it may rearrange itself inconsistently between versions... but it's technically not incorrect I think. Just some thoughts, other people may be able to speak with more authority on the paradigm. $\endgroup$ – user6014 Oct 12 '16 at 15:21
  • $\begingroup$ @user6014 Yes, all data structures in Mathematica are ordered, including associations. What functions operating on them do is a separate issue. The documentation of GroupBy doesn't say anything about ordering. This contrasts with GatherBy, which keeps the ordering intact according to its docs. BTW there's no need for Dataset to reproduce this, just a GroupBy on the underlying list of associations will do. $\endgroup$ – Szabolcs Oct 12 '16 at 15:41
  • 1
    $\begingroup$ Contacted WRI to see what they have to say about it. I think it is a bug since it was working before and version 11.0.0/1 have a few meaty bugs as it concerns Datasets. $\endgroup$ – Edmund Oct 12 '16 at 18:02

Your Answer

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

Browse other questions tagged or ask your own question.