Bug introduced in 10.0 and fixed in 10.1.0
In Version 10, the GeneralUtilities package contain some useful functions. AssociatePairs is one of those functions included in the package and advertised to work as follows:
Needs["GeneralUtilities`"]
?AssociatePairs

Well, here is an input that matches a List of pairs:
lis = Table[{k, k^3}, {k, 2, 10}];
Now,
AssociatePairs[lis]
Gives the following error:

Well, the included PairQ function disagrees with this assertion:
AllTrue[lis, PairQ]
True
So, is this a bug? Since I can't get any list of pairs to work with this function. I'm on Windows 8.1
Answer
Using Simon Woods's Spelunk we see that the body of the function is:
Self : AssociatePairs[l_] :=
Module[{r$},
r$ = Which[! Quiet[TrueQ[MatrixQ[l, PairQ]]], Message[AssociatePairs::npairs, l];
$FailRHS, True, HoldSequence[Associate @@ Transpose[l]]];
ReleaseHoldSequence[r$] /; ! MatchQ[r$, $FailRHS | HoldSequence[$FailRHS]]
]
I draw your attention to:
TrueQ[MatrixQ[l, PairQ]]
Recalling the definition of MatrixQ:

This means that the function is checking that:
l(input) is a matrixeach element passes
PairQ
This is apparently illogical.
One could correct this with one of many other possible checks, simplest perhaps:
MatchQ[l, {{_, _} ..}]
Or to allow for SparseArray input, as may have been the motivation for MatrixQ:
MatchQ[Dimensions[l], {_, 2}] && MatrixQ[l]
Comments
Post a Comment