9
$\begingroup$

Consider this example:

ds = Dataset @ Transpose[<|"a" -> {1, 2, 3, 4, 3, 2, 1}, "b" -> {6, 5, 4, 3, 2, 1, 0}|>,
                         AllowedHeads -> All]

Mathematica graphics

Now say I need to work with the ratios of these two values. This works fine:

ds[;;-2, #a/#b &]

Mathematica graphics

But this fails:

ds[All, #a/#b &]

Mathematica graphics

It would be easier for me to just get a result with some ComplexInfinities. Does the operation fail by desgin or oversight? Is there a workaround? Should I just use

ds[All, Quiet[#a/#b] &]

all the time or is there a more general solution? Off[General::infy] doesn't prevent this from failing, though the failure message can't be displayed properly.

$\endgroup$
3
  • $\begingroup$ I'd upvote this if it weren't deleted. :^) $\endgroup$
    – Mr.Wizard
    Aug 4, 2014 at 21:53
  • $\begingroup$ @Mr.Wizard Undeleted because I just discovered FailureAction. $\endgroup$
    – Szabolcs
    Aug 4, 2014 at 21:55
  • $\begingroup$ Post it! :-) .. $\endgroup$
    – Mr.Wizard
    Aug 4, 2014 at 21:56

1 Answer 1

12
$\begingroup$

One possible solution is using Quiet:

ds[All, Quiet[#a/#b]&]

Another possible solution is using the FailureAction option:

ds[All, #a/#b, FailureAction -> None]
$\endgroup$
4
  • $\begingroup$ Why CW? Seems like a good self-answer to me. shrug $\endgroup$
    – Mr.Wizard
    Aug 4, 2014 at 21:57
  • $\begingroup$ I'll delete this if someone writes a comprehensive answer. Just collecting here what I find as I progress ... $\endgroup$
    – Szabolcs
    Aug 4, 2014 at 21:57
  • $\begingroup$ @Mr.Wizard I don't want to discourage other answers. I'm just learning to use Dataset. I didn't need to use it before. Now I have a good application. $\endgroup$
    – Szabolcs
    Aug 4, 2014 at 21:57
  • $\begingroup$ I think FailureAction is your best option here. $\endgroup$
    – rcollyer
    Aug 5, 2014 at 1:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.