# Why does an inert ReplaceAll modify this Dataset?

I cannot see any reason for this behavior besides a bug, but I've been wrong before so I put it before the community:

ds = Dataset[{
<|"ID" -> "Alpha", "v1" -> 1, "v2" -> 0|>,
<|"ID" -> "Beta" , "v1" -> 1, "v2" -> 1|>,
<|"ID" -> "Alpha", "v1" -> 1, "v2" -> 0|>}];

ds[Select[#"ID" == "Alpha" &], {"ID"}]

% /. {}


The internal structure changed in from:

Dataset[{<|"ID" -> "Alpha"|>, <|"ID" -> "Alpha"|>},
TypeSystemVector[TypeSystemStruct[{"ID"}, {TypeSystemAtom[String]}],
TypeSystemAnyLength], <|
"Origin" ->
HoldComplete[
Query[Select[#ID == "Alpha" &], {"ID"}][DatasetDatasetHandle[43190226294398]]],
"ID" -> 96078453577381|>]


To:

Dataset[{<|"ID" -> "Alpha"|>, <|"ID" -> "Alpha"|>},
TypeSystemVector[TypeSystemAssoc[TypeSystemAtom[String], TypeSystemAtom[String], 1],
2], <|"Origin" -> HoldComplete[DatasetDatasetHandle[96078453577381] /. {}],
"ID" -> 3384469395109|>]

1. Why the change?

2. Why does this change affect the output formatting?

In the first case, the type of the dataset was deduced via type deduction mechanism applied at Dataset construction. In the second case, it was inferred using a set of type inference rules. The fact that this happens even with inert replacement does not matter: as long as ReplaceAll is used, type of the resulting Dataset is inferred rather than deduced.
In some cases, type inference isn't yet able to do as good a job as type deduction, which results in more generic types. This is what we see here. It may still be considered a bug (Taliesin Beynon is the one to confirm this). As to the output formatting, it is tied to the type of the Dataset. In the first case, it uses specialized formatting rules for type Struct, in the last case - generic formatting for associations.
• To expand on this a bit: the fact that the Assoc result isn't typeset as nicely as the Struct is a bug that Tali wants to fix. – Stefan R Feb 12 '15 at 19:52