def to_mojo(self,
             mojo: MojoWriter,
             iframe: MojoFrame,
             group_uuid=None,
             group_name=None):
     from h2oaicore.mojo import MojoColumn, MojoFrame, MojoType
     import uuid
     group_uuid = str(uuid.uuid4())
     group_name = "RoundTransformer"
     kws = dict()
     kws["op_name"] = "round"
     custom_param = dict()
     custom_param["decimals"] = (MojoType.INT32, self.decimals)
     kws["op_params"] = custom_param
     from h2oaicore.mojo_transformers import MjT_CustomOp
     from h2oaicore.mojo_transformers_utils import AsType
     xnew = iframe[self.input_feature_names]
     oframe = MojoFrame()
     for col in xnew:
         ocol = MojoColumn(name=col.name, dtype=col.type)
         ocol_frame = MojoFrame(columns=[ocol])
         mojo += MjT_CustomOp(iframe=MojoFrame(columns=[col]),
                              oframe=ocol_frame,
                              group_uuid=group_uuid,
                              group_name=group_name,
                              **kws)
         oframe += ocol
     oframe = AsType(dtype_global()).write_to_mojo(mojo,
                                                   oframe,
                                                   group_uuid=group_uuid,
                                                   group_name=group_name)
     return oframe
 def to_mojo(self,
             mojo: MojoWriter,
             iframe: MojoFrame,
             group_uuid=None,
             group_name=None):
     import uuid
     group_uuid = str(uuid.uuid4())
     group_name = self.__class__.__name__
     from h2oaicore.mojo import MojoColumn, MojoFrame
     from h2oaicore.mojo_transformers import MjT_Log
     from h2oaicore.mojo_transformers_utils import AsType
     xnew = iframe[self.input_feature_names]
     oframe = MojoFrame()
     for col in xnew:
         ocol = MojoColumn(name=col.name, dtype=np.float64)
         ocol_frame = MojoFrame(columns=[ocol])
         mojo += MjT_Log(iframe=MojoFrame(columns=[col]),
                         oframe=ocol_frame,
                         group_uuid=group_uuid,
                         group_name=group_name)
         oframe += ocol
     oframe = AsType(dtype_global()).write_to_mojo(mojo,
                                                   oframe,
                                                   group_uuid=group_uuid,
                                                   group_name=group_name)
     return oframe
Exemple #3
0
    def write_to_mojo(self, mojo: MojoWriter, iframe: MojoFrame):

        iframe = iframe[self.time_column]
        icol = iframe.get_column(0)
        if icol.type != MojoType.STR:
            iframe = AsType("int").write_to_mojo(mojo, iframe)
            iframe = AsType("str").write_to_mojo(mojo, iframe)
            icol = iframe.get_column(0)

        # We have to add each holiday to the MOJO
        oframe = MojoFrame()
        for prov in ['country', 'BW', 'BY', 'BE', 'BB', 'HB', 'HH', 'HE', 'MV',
                     'NI', 'NW', 'RP', 'SL', 'SN', 'ST', 'SH', 'TH']:
            tmpframe = iframe.duplicate()
            mojo += MjT_Replace(iframe=iframe, oframe=tmpframe, map=[('None', None), ('', None)])
            tcol = tmpframe.get_column(0)
            datetime_format = self.datetime_formats[self.time_column]
            if datetime_format is not None:
                mojo.set_datetime_format_str(tcol, datetime_format)
            iframe = tmpframe
            tframe = AsType("datetime64").write_to_mojo(mojo, iframe)
            year_col = MojoColumn(name="year", dtype="int")
            doy_col = MojoColumn(name="doy", dtype="int")
            mojo += MjT_Datepart(iframe=tframe, oframe=MojoFrame(columns=[year_col]), fn="year")
            mojo += MjT_Datepart(iframe=tframe, oframe=MojoFrame(columns=[doy_col]), fn="dayofyear")
            dates_frame = MojoFrame(columns=[year_col, doy_col])
            feat = f'is_DE_holiday_{prov}'
            holi_df = self.memos[prov]
            holi_df[feat] = 1
            mout = MergeTransformer.from_frame(
                holi_df, ['year', 'doy']).write_to_mojo(mojo, dates_frame)
            holi_df.drop(feat, axis=1, inplace=True)

            mlag = mout[feat]
            mlag.names = [feat]
            olag = mlag.get_column(0).duplicate()
            mojo += MjT_FillNa(iframe=mlag, oframe=MojoFrame(columns=[olag]),
                               repl=olag.pytype(0))
            oframe += olag

        # print(oframe.names)
        oframe = AsType("int").write_to_mojo(mojo, oframe)
        # print(oframe.names)
        return oframe
Exemple #4
0
 def to_mojo(self, mojo: MojoWriter, iframe: MojoFrame):
     from h2oaicore.mojo import MojoColumn, MojoFrame
     from h2oaicore.mojo_transformers import MjT_Log
     from h2oaicore.mojo_transformers_utils import AsType
     from h2oaicore.systemutils import dtype_global
     xnew = iframe[self.input_feature_names]
     oframe = MojoFrame()
     for col in xnew:
         ocol = MojoColumn(name=col.name, dtype=np.float64)
         ocol_frame = MojoFrame(columns=[ocol])
         mojo += MjT_Log(iframe=MojoFrame(columns=[col]), oframe=ocol_frame)
         oframe += ocol
     oframe = AsType(dtype_global()).write_to_mojo(mojo, oframe)
     return oframe