@pandas_udf(p1, PandasUDFType.GROUPED_MAP)
def _trend(key, data):
    dates = [(str((int(start[0:4]) - 3)) + '0831'), (str((int(start[0:4]) - 3)) + '1031'), (str((int(start[0:4]) - 2)) + '0431'), (str((int(start[0:4]) - 2)) + '0831'), (str((int(start[0:4]) - 2)) + '1031'), (str((int(start[0:4]) - 1)) + '0431'), (str((int(start[0:4]) - 1)) + '0831'), (str((int(start[0:4]) - 1)) + '1031')]
    _lam_f = (lambda x, y: (y[(y.trade_date <= x)].iloc[(- 1)] if (y[(y.trade_date <= x)].shape[0] > 0) else None))
    resampledf = pd.DataFrame(list(filter((lambda x: (x is not None)), map(_lam_f, dates, ([data] * 8)))))
    col = ['trade_date', 'industry']
    col = (col + new_struct)
    indicator = pd.DataFrame(columns=col)
    df = data[(data.trade_date >= start)]
    df.reset_index(drop=True)
    for (index, item) in df.iterrows():
        if ((item.trade_date[4:8] <= '0831') and (item.trade_date[4:8] > '0431') and ((item.trade_date[0:4] + '0431') not in dates)):
            dates.append([(item.trade_date[0:4] + '0431')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '0431')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        if ((item.trade_date[4:8] <= '1031') and (item.trade_date[4:8] > '0831') and ((item.trade_date[0:4] + '0831') not in dates)):
            dates.append([(item.trade_date[0:4] + '0831')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '0831')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        if ((item.trade_date[4:8] > '1031') and ((item.trade_date[0:4] + '1031') not in dates)):
            dates.append([(item.trade_date[0:4] + '1031')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '1031')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        resample = resampledf.append(list(map(_lam_f, [item.trade_date], [data])))
        resample = resample.dropna(how='all')
        ind = ((- 8) if (resample.shape[0] > 8) else (- resample.shape[0]))
        (fit, p3) = RegUtil.regress_y_polynomial(resample[ind:].q_dtprofit_ttm, poly=3, show=False)
        (fit, p5) = RegUtil.regress_y_polynomial(resample[ind:].q_gr, poly=3, show=False)
        (fit, p6) = RegUtil.regress_y_polynomial(resample[ind:].q_profit, poly=3, show=False)
        (fit, p7) = RegUtil.regress_y_polynomial(resample[ind:].q_dtprofit, poly=3, show=False)
        (fit, p8) = RegUtil.regress_y_polynomial(resample[ind:].q_opincome, poly=3, show=False)
        roe = (item.q_dtprofit / item.total_hldr_eqy_exc_min_int)
        pe = ((item.ind_total_mv * 10000) / item.q_dtprofit)
        roe_ttm = (item.q_dtprofit_ttm / item.total_hldr_eqy_exc_min_int)
        pe_ttm = ((item.ind_total_mv * 10000) / item.q_dtprofit_ttm)
        indicator.loc[index] = [item.trade_date, key[0], p3(8), p5(8), p6(8), p7(8), p8(8), roe, pe, roe_ttm, pe_ttm]
    return indicator
@pandas_udf(p1, PandasUDFType.GROUPED_MAP)
def _trend(key, data):
    dates = [(str((int(start[0:4]) - 3)) + '0831'), (str((int(start[0:4]) - 3)) + '1031'), (str((int(start[0:4]) - 2)) + '0431'), (str((int(start[0:4]) - 2)) + '0831'), (str((int(start[0:4]) - 2)) + '1031'), (str((int(start[0:4]) - 1)) + '0431'), (str((int(start[0:4]) - 1)) + '0831'), (str((int(start[0:4]) - 1)) + '1031')]
    _lam_f = (lambda x, y: (y[(y.trade_date <= x)].iloc[(- 1)] if (y[(y.trade_date <= x)].shape[0] > 0) else None))
    resampledf = pd.DataFrame(list(filter((lambda x: (x is not None)), map(_lam_f, dates, ([data] * 8)))))
    col = ['trade_date', 'industry']
    col = (col + new_struct)
    indicator = pd.DataFrame(columns=col)
    df = data[(data.trade_date >= start)]
    df.reset_index(drop=True)
    for (index, item) in df.iterrows():
        if ((item.trade_date[4:8] <= '0831') and (item.trade_date[4:8] > '0431') and ((item.trade_date[0:4] + '0431') not in dates)):
            dates.append([(item.trade_date[0:4] + '0431')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '0431')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        if ((item.trade_date[4:8] <= '1031') and (item.trade_date[4:8] > '0831') and ((item.trade_date[0:4] + '0831') not in dates)):
            dates.append([(item.trade_date[0:4] + '0831')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '0831')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        if ((item.trade_date[4:8] > '1031') and ((item.trade_date[0:4] + '1031') not in dates)):
            dates.append([(item.trade_date[0:4] + '1031')])
            t = list(filter((lambda x: (x is not None)), map(_lam_f, [(item.trade_date[0:4] + '1031')], [data])))
            if (t is not None):
                resampledf = resampledf.append(t)
        resample = resampledf.append(list(map(_lam_f, [item.trade_date], [data])))
        resample = resample.dropna(how='all')
        ind = ((- 8) if (resample.shape[0] > 8) else (- resample.shape[0]))
        (fit, p3) = RegUtil.regress_y_polynomial(resample[ind:].q_dtprofit_ttm, poly=3, show=False)
        (fit, p5) = RegUtil.regress_y_polynomial(resample[ind:].q_gr, poly=3, show=False)
        (fit, p6) = RegUtil.regress_y_polynomial(resample[ind:].q_profit, poly=3, show=False)
        (fit, p7) = RegUtil.regress_y_polynomial(resample[ind:].q_dtprofit, poly=3, show=False)
        (fit, p8) = RegUtil.regress_y_polynomial(resample[ind:].q_opincome, poly=3, show=False)
        roe = (item.q_dtprofit / item.total_hldr_eqy_exc_min_int)
        pe = ((item.ind_total_mv * 10000) / item.q_dtprofit)
        roe_ttm = (item.q_dtprofit_ttm / item.total_hldr_eqy_exc_min_int)
        pe_ttm = ((item.ind_total_mv * 10000) / item.q_dtprofit_ttm)
        indicator.loc[index] = [item.trade_date, key[0], p3(8), p5(8), p6(8), p7(8), p8(8), roe, pe, roe_ttm, pe_ttm]
    return indicator