Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
I'd upvote this if it weren't deleted. :^) –  Mr.Wizard Aug 4 at 21:53
    
@Mr.Wizard Undeleted because I just discovered FailureAction. –  Szabolcs Aug 4 at 21:55
    
Post it! :-) .. –  Mr.Wizard Aug 4 at 21:56

1 Answer 1

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]
share|improve this answer
    
Why CW? Seems like a good self-answer to me. shrug –  Mr.Wizard Aug 4 at 21:57
    
I'll delete this if someone writes a comprehensive answer. Just collecting here what I find as I progress ... –  Szabolcs Aug 4 at 21:57
    
@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. –  Szabolcs Aug 4 at 21:57
    
I think FailureAction is your best option here. –  rcollyer Aug 5 at 1:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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