Skip to content

Commit

Permalink
feat(pandas): implement trig functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed May 19, 2022
1 parent 01e7ce7 commit 1fd52d2
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion ibis/backends/pandas/execution/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def execute_sort_key_series_bool(op, data, ascending, **kwargs):


def call_numpy_ufunc(func, op, data, **kwargs):
if data.dtype == np.dtype(np.object_):
if getattr(data, "dtype", None) == np.dtype(np.object_):
return data.apply(functools.partial(execute_node, op, **kwargs))
return func(data)

Expand Down Expand Up @@ -215,6 +215,42 @@ def execute_series_unary_op(op, data, **kwargs):
return call_numpy_ufunc(function, op, data, **kwargs)


@execute_node.register(ops.Acos, (pd.Series, *numeric_types))
def execute_series_acos(_, data, **kwargs):
return np.arccos(data)


@execute_node.register(ops.Asin, (pd.Series, *numeric_types))
def execute_series_asin(_, data, **kwargs):
return np.arcsin(data)


@execute_node.register(ops.Atan, (pd.Series, *numeric_types))
def execute_series_atan(_, data, **kwargs):
return np.arctan(data)


@execute_node.register(ops.Cot, (pd.Series, *numeric_types))
def execute_series_cot(_, data, **kwargs):
return np.cos(data) / np.sin(data)


@execute_node.register(
ops.Atan2, (pd.Series, *numeric_types), (pd.Series, *numeric_types)
)
def execute_series_atan2(_, y, x, **kwargs):
return np.arctan2(y, x)


@execute_node.register(
(ops.Cos, ops.Sin, ops.Tan),
(pd.Series, *numeric_types),
)
def execute_series_trig(op, data, **kwargs):
function = getattr(np, type(op).__name__.lower())
return call_numpy_ufunc(function, op, data, **kwargs)


@execute_node.register((ops.Ceil, ops.Floor), pd.Series)
def execute_series_ceil(op, data, **kwargs):
return_type = np.object_ if data.dtype == np.object_ else np.int64
Expand Down

0 comments on commit 1fd52d2

Please sign in to comment.