data-science

pwrflx 2025-01-04T09:32:08.683309Z

When doing a / operator on two columns in tablecloth, I get an ArithmeticException due to "Non-terminating decimal expansion; no exact representable decimal result.". In plain clojuse you solve this with (with-precision .. ) however due to tech datatype operating on another thread simply doing (with-precision 5 (tc// does not work. Any idea?

Daniel Slutsky 2025-01-04T09:36:39.933429Z

Hi. It would be helpful to provide a reproducible example we could explore.

👍 1
pwrflx 2025-01-04T09:39:32.316629Z

(-> (tablecloth.api/dataset {:A [(bigdec 10)]  
                             :B [(bigdec 3)]})
    (tablecloth.api// :C [:A :B])
    )

Daniel Slutsky 2025-01-04T10:40:16.208869Z

Thanks. It is an intresting proposal to extend column arithmetic to bigdec. This actually relates to the undelying dtype-next library. I'd recommend discussing it with the library authors at the # channel of the Clojurians Zulip chat. For now, you can use tc/map-columns.

(with-precision
  5
  (-> (tablecloth.api/dataset {:A [(bigdec 10)]  
                               :B [(bigdec 3)]})
      (tablecloth.api/map-columns
       :C
       [:A :B]
       /)))

pwrflx 2025-01-04T10:47:50.461789Z

OK, thank you! In general do you recommend against using bigdec in tablecloth datasets? I use monetary values and for that usually bigdecimal is the standard practice

Daniel Slutsky 2025-01-04T10:50:50.804739Z

You can use any value inside datasets. I think it just means you will not be able to enjoy the performance benefits (memory and time) you would have with primitive numeric types.

pwrflx 2025-01-04T10:51:43.917469Z

I see, maybe I'll do a test and switch to double and see how precision degrades and speed/memory improves

👍 1
pwrflx 2025-01-04T10:51:51.030469Z

thank you