# Strange result of DeleteCases in an association

Bug introduced in 10.1.0 and fixed in 10.3.1

The function DeleteCases can be used for associations, also with level specification. Here is an example where some values are associations:

asc = Association["a" -> Association[], "b" -> Association["c" -> Association[1 -> 1]]]

(* <|a -> <||>, b -> <|c -> <|1 -> 1|>|>|> *)


Deleting on level 1 works:

DeleteCases[asc, _Association]

(* <||> *)


Deleting on level 2 works as well:

DeleteCases[asc, _Association, {2}]

(* <|a -> <||>, b -> <||>|> *)


But deleting on both levels does not return what I would expect:

DeleteCases[asc, _Association, {1,2}]

(* <|a -> <||>|> *)


I cannot figure out why this happens. Is this a bug or intended behaviour?

• With MMa 10.1.0 under Win7 x64 I get <||> both for DeleteCases[asc, _Association, {1, 2}] and DeleteCases[asc, _Association, 2]. Which version do you use? – Alexey Popkov Jul 7 '15 at 11:24
• @Alexey. Many thanks for your prompt reaction. I use version 10.1.0 on Windows 32-bit. When I restarted my computer and verified the result with a fresh kernel, I was shocked to see the same output as yours. I ran into this problem quite often the last few days, and fortunately I could edit my question such that the unexpect result now also appears with a fresh kernel. Do you mind to test it once again? – Fred Simons Jul 7 '15 at 11:50
• With you updated example I get the same output as yours. Looks like a bug indeed. – Alexey Popkov Jul 7 '15 at 11:58