9

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263

1 Answers1

12

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]
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263