2525import pytest
2626import random
2727import datatable as dt
28- from datatable import f , g , stype , join
28+ from datatable import dt , f , g , stype , join
2929from datatable .internal import frame_integrity_check
3030from tests import assert_equals
31+ from itertools import product , islice
3132
3233
3334# Sets of tuples containing test columns of each type
@@ -220,3 +221,56 @@ def test_log_srcs(src, fn):
220221 mathlog (x )
221222 for x in src ]
222223 assert DT1 .to_list ()[0 ] == pyans
224+
225+
226+ #-------------------------------------------------------------------------------
227+ # Unary hyperbolic
228+ #-------------------------------------------------------------------------------
229+
230+ def hyperbolic_func (func , t ):
231+ if t is None : return None
232+ return func (t )
233+
234+
235+ funcs = [math .sinh , math .cosh , math .tanh ]
236+ dt_funcs = [dt .math .sinh , dt .math .cosh , dt .math .tanh ]
237+
238+ @pytest .mark .parametrize ("math_func, dt_func" , zip (funcs , dt_funcs ))
239+ def test_dt_hyperbolic1 (math_func , dt_func ):
240+ srcs = srcs_bool + srcs_int [:2 ]
241+ DT = dt .Frame (srcs )
242+ RES = DT [:, dt_func (f [:])]
243+ frame_integrity_check (RES )
244+ assert RES .to_list () == [[hyperbolic_func (math_func , x ) for x in src ] for src in srcs ]
245+
246+ def test_dt_hyperbolic_acosh ():
247+ srcs = [[7 , 56 , 2.45 , 1 ]]
248+ DT = dt .Frame (srcs )
249+ RES = DT [:, dt .math .arcosh (f [:])]
250+ frame_integrity_check (RES )
251+ assert RES .to_list () == [[hyperbolic_func (math .acosh , x ) for x in src ] for src in srcs ]
252+
253+ def test_dt_hyperbolic_atanh ():
254+ srcs = [[0.59 , - 0.12 , 0.00008 ]]
255+ DT = dt .Frame (srcs )
256+ RES = DT [:, dt .math .artanh (f [:])]
257+ frame_integrity_check (RES )
258+ assert RES .to_list () == [[hyperbolic_func (math .atanh , x ) for x in src ] for src in srcs ]
259+
260+ def test_dt_hyperbolic_asinh ():
261+ srcs = [[0.59 , - 0.12 , 0.00008 ]]
262+ DT = dt .Frame (srcs )
263+ RES = DT [:, dt .math .arsinh (f [:])]
264+ frame_integrity_check (RES )
265+ assert RES .to_list () == [[hyperbolic_func (math .asinh , x ) for x in src ] for src in srcs ]
266+
267+ funcs = [math .sinh , math .cosh , math .tanh , math .acosh , math .asinh , math .atanh ]
268+ funcs = product (dt_funcs , srcs_str )
269+ @pytest .mark .parametrize ("dt_func, src" , funcs )
270+ def test_dt_hyperbolic_invalid (dt_func , src ):
271+ DT = dt .Frame (src )
272+ col_stype = DT .stype .name
273+ fn_name = dt_func .__name__
274+ with pytest .raises (TypeError , match = f"Function { fn_name } cannot be applied to a "
275+ f"column of type { col_stype } " ):
276+ assert DT [:, dt_func (f [0 ])]
0 commit comments