-
Notifications
You must be signed in to change notification settings - Fork 233
/
functions.py
33 lines (27 loc) · 1.06 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from optimus.engines.base.basedataframe import BaseDataFrame
import numpy as np
class Functions(type):
"""
Handle the method name and execute the function corresponding to the dataframe class
"""
def __getattr__(self, func):
"""
:param func: Method name
:return:
"""
def _func(df_or_value, *args):
# Get the internal series in the optimus dataframe
# print("df_or_value",type(df_or_value),df_or_value)
if isinstance(df_or_value, BaseDataFrame):
_df = df_or_value.data[df_or_value.cols.names(0)[0]]
# Convert the frame to a dataframe and to a optimus Dataframe
return df_or_value.__class__(getattr(df_or_value.functions, func)(_df, *args).to_frame())
else:
return getattr(np, func)(df_or_value, *args)
return _func
class F(metaclass=Functions):
"""
Dummy class to handle method names
For example: In F.sqrt, sqrt is captured and mapped a matched to the function dataframe
"""
pass