# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/utils/input_validation.py
# @expect_types(arg=(list, np.ndarray, pd.DataFrame, pd.Series))
# def ensure_pd_df(func, argname, arg):
#     if isinstance(arg, pd.DataFrame):
#         return arg
#     else:
#         return pd.DataFrame(arg)


import pandas as pd
import numpy as np
from argcheck import (expect_types,
                      optional,
                      preprocess)
from xutils import py_assert
from alphaware.const import INDEX_FACTOR
from alphaware.enums import (FreqType,
                             OutputDataFormat)
from .input_validation import ensure_pd_df
    if target_format == OutputDataFormat.MULTI_INDEX_DF:
        tmp = data.stack()
        data_ = pd.DataFrame(tmp)
        data_.index.names = multi_index.full_index
        data_.columns = [col_name]
    else:
        tmp = data.unstack()
        index = tmp.index
        columns = tmp.columns.get_level_values(multi_index.sec_index).tolist()
        data_ = pd.DataFrame(tmp.values, index=index, columns=columns)

    return data_


@expect_types(df=(pd.Series, pd.DataFrame))
def top(df, column=None, n=5):
    if isinstance(df, pd.Series):
        ret = df.sort_values(ascending=False)[:n]
    else:
        py_assert(column is not None, "Specify the col name or use pandas Series type of data")
        ret = df.sort_values(by=column, ascending=False)[:n]

    return ret


@expect_types(data=(pd.DataFrame, pd.Series), freq=optional(FreqType, str))
def group_by_freq(data, freq=FreqType.EOM):
    data_ = pd.DataFrame(data) if isinstance(data, pd.Series) else data
    if freq == FreqType.EOD:
        return data_.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day])

# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/utils/input_validation.py
# @expect_types(arg=(list, np.ndarray, pd.DataFrame, pd.Series))
# def ensure_pd_df(func, argname, arg):
#     if isinstance(arg, pd.DataFrame):
#         return arg
#     else:
#         return pd.DataFrame(arg)


# Path: alphaware/utils/pandas_utils.py
import pandas as pd
import numpy as np
from argcheck import (expect_types,
                      optional,
                      preprocess)
from xutils import py_assert
from alphaware.const import INDEX_FACTOR
from alphaware.enums import (FreqType,
                             OutputDataFormat)
from .input_validation import ensure_pd_df

    if target_format == OutputDataFormat.MULTI_INDEX_DF:
        tmp = data.stack()
        data_ = pd.DataFrame(tmp)
        data_.index.names = multi_index.full_index
        data_.columns = [col_name]
    else:
        tmp = data.unstack()
        index = tmp.index
        columns = tmp.columns.get_level_values(multi_index.sec_index).tolist()
        data_ = pd.DataFrame(tmp.values, index=index, columns=columns)

    return data_


@expect_types(df=(pd.Series, pd.DataFrame))
def top(df, column=None, n=5):
    if isinstance(df, pd.Series):
        ret = df.sort_values(ascending=False)[:n]
    else:
        py_assert(column is not None, "Specify the col name or use pandas Series type of data")
        ret = df.sort_values(by=column, ascending=False)[:n]

    return ret


@expect_types(data=(pd.DataFrame, pd.Series), freq=optional(FreqType, str))
def group_by_freq(data, freq=FreqType.EOM):
    data_ = pd.DataFrame(data) if isinstance(data, pd.Series) else data
    if freq == FreqType.EOD:
        return data_.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day])

    elif freq == FreqType.EOM: