# Path: alphaware/utils/input_validation.py
# @expect_types(arg=(list, np.ndarray, pd.DataFrame, pd.Series))
# def ensure_pd_series(func, argname, arg):
#     if isinstance(arg, pd.Series):
#         return arg
#     elif isinstance(arg, pd.DataFrame):
#         return arg[arg.columns[0]]
#     else:
#         return pd.Series(arg)
# 
# @expect_types(date=(str, datetime, Date))
# def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
#     """
#     :param date: str, datetime, 日期
#     :param date_format: str, 时间格式
#     :return: PyFin.Date object 
#     """
#     if isinstance(date, Date):
#         return date
#     elif isinstance(date, str):
#         return Date.strptime(date, date_format)
#     else:
#         return Date.fromDateTime(date)
# 
# @expect_types(arg=(np.ndarray, pd.DataFrame, pd.Series))
# def ensure_np_array(func, argname, arg):
#     """
#     :return: 转换成np.ndarray格式
#     """
#     if isinstance(arg, np.ndarray):
#         return arg
#     else:
#         return arg.values
# 
# @expect_types(data=(pd.DataFrame, pd.Series), data_format=OutputDataFormat)
# def ensure_pd_index_names(data, data_format, valid_index):
#     if data_format == OutputDataFormat.MULTI_INDEX_DF:
#         data.index.names = valid_index.full_index
#     else:
#         data.index.name = valid_index.date_index
#     return data
# 
# Path: alphaware/enums.py
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# INDEX_INDUSTRY_WEIGHT = namedtuple('INDEX_INDUSTRY_WEIGHT',
#                                    ['date_index', 'industry_index', 'full_index', 'col_name'])


from unittest import TestCase
from parameterized import parameterized
from numpy.testing.utils import assert_array_equal
from xutils.date_utils import Date
from pandas.util.testing import (assert_series_equal,
                                 assert_frame_equal)
from alphaware.utils import (ensure_pd_series,
                             ensure_pyfin_date,
                             ensure_np_array,
                             ensure_pd_index_names)
from alphaware.enums import OutputDataFormat
from alphaware.const import (INDEX_FACTOR,
                             INDEX_INDUSTRY_WEIGHT)
import pandas as pd
import numpy as np
                           (pd.Series([1, 2, 3]), pd.Series([1, 2, 3]))
                           ])
    def test_ensure_pd_series(self, data, expected):
        calculated = ensure_pd_series(None, None, data)
        assert_series_equal(calculated, expected)

    @parameterized.expand([('2014-01-02', '%Y-%m-%d', Date(2014, 1, 2)),
                           ('2013/05/02', '%Y/%m/%d', Date(2013, 5, 2)),
                           (Date(2013, 5, 2), '%Y/%m/%d', Date(2013, 5, 2))])
    def test_ensure_pyfin_date(self, data, date_format, expected):
        calculated = ensure_pyfin_date(data, date_format)
        self.assertEqual(calculated, expected)

    @parameterized.expand([(None, None, pd.Series([1, 2, 3]), np.array([1, 2, 3])),
                           (None, None, pd.DataFrame([[1, 2, 3], [2, 3, 4]]), np.array([[1, 2, 3], [2, 3, 4]])),
                           (None, None, np.array([1, 2, 3]), np.array([1, 2, 3]))])
    def test_ensure_np_array(self, func, argname, data, expected):
        calculated = ensure_np_array(func, argname, data)
        assert_array_equal(calculated, expected)

    @parameterized.expand([(pd.DataFrame([1, 2],
                                         index=pd.MultiIndex.from_product([['2010-01-01', '2010-01-02'], ['001']],
                                                                          names=['trade_date', 'sec'])),
                            OutputDataFormat.MULTI_INDEX_DF,
                            INDEX_INDUSTRY_WEIGHT,
                            pd.DataFrame([1, 2],
                                         index=pd.MultiIndex.from_product([['2010-01-01', '2010-01-02'], ['001']],
                                                                          names=['trade_date', 'industry_code'])
                                         )),
                           (pd.DataFrame([1, 2], index=pd.Index(['2010-01-01', '2010-01-02'], name='trade_date')),

# Path: alphaware/utils/input_validation.py
# @expect_types(arg=(list, np.ndarray, pd.DataFrame, pd.Series))
# def ensure_pd_series(func, argname, arg):
#     if isinstance(arg, pd.Series):
#         return arg
#     elif isinstance(arg, pd.DataFrame):
#         return arg[arg.columns[0]]
#     else:
#         return pd.Series(arg)
# 
# @expect_types(date=(str, datetime, Date))
# def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
#     """
#     :param date: str, datetime, 日期
#     :param date_format: str, 时间格式
#     :return: PyFin.Date object 
#     """
#     if isinstance(date, Date):
#         return date
#     elif isinstance(date, str):
#         return Date.strptime(date, date_format)
#     else:
#         return Date.fromDateTime(date)
# 
# @expect_types(arg=(np.ndarray, pd.DataFrame, pd.Series))
# def ensure_np_array(func, argname, arg):
#     """
#     :return: 转换成np.ndarray格式
#     """
#     if isinstance(arg, np.ndarray):
#         return arg
#     else:
#         return arg.values
# 
# @expect_types(data=(pd.DataFrame, pd.Series), data_format=OutputDataFormat)
# def ensure_pd_index_names(data, data_format, valid_index):
#     if data_format == OutputDataFormat.MULTI_INDEX_DF:
#         data.index.names = valid_index.full_index
#     else:
#         data.index.name = valid_index.date_index
#     return data
# 
# Path: alphaware/enums.py
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# INDEX_INDUSTRY_WEIGHT = namedtuple('INDEX_INDUSTRY_WEIGHT',
#                                    ['date_index', 'industry_index', 'full_index', 'col_name'])


# Path: alphaware/tests/utils/test_input_validation.py
from unittest import TestCase
from parameterized import parameterized
from numpy.testing.utils import assert_array_equal
from xutils.date_utils import Date
from pandas.util.testing import (assert_series_equal,
                                 assert_frame_equal)
from alphaware.utils import (ensure_pd_series,
                             ensure_pyfin_date,
                             ensure_np_array,
                             ensure_pd_index_names)
from alphaware.enums import OutputDataFormat
from alphaware.const import (INDEX_FACTOR,
                             INDEX_INDUSTRY_WEIGHT)
import pandas as pd
import numpy as np

                           (pd.Series([1, 2, 3]), pd.Series([1, 2, 3]))
                           ])
    def test_ensure_pd_series(self, data, expected):
        calculated = ensure_pd_series(None, None, data)
        assert_series_equal(calculated, expected)

    @parameterized.expand([('2014-01-02', '%Y-%m-%d', Date(2014, 1, 2)),
                           ('2013/05/02', '%Y/%m/%d', Date(2013, 5, 2)),
                           (Date(2013, 5, 2), '%Y/%m/%d', Date(2013, 5, 2))])
    def test_ensure_pyfin_date(self, data, date_format, expected):
        calculated = ensure_pyfin_date(data, date_format)
        self.assertEqual(calculated, expected)

    @parameterized.expand([(None, None, pd.Series([1, 2, 3]), np.array([1, 2, 3])),
                           (None, None, pd.DataFrame([[1, 2, 3], [2, 3, 4]]), np.array([[1, 2, 3], [2, 3, 4]])),
                           (None, None, np.array([1, 2, 3]), np.array([1, 2, 3]))])
    def test_ensure_np_array(self, func, argname, data, expected):
        calculated = ensure_np_array(func, argname, data)
        assert_array_equal(calculated, expected)

    @parameterized.expand([(pd.DataFrame([1, 2],
                                         index=pd.MultiIndex.from_product([['2010-01-01', '2010-01-02'], ['001']],
                                                                          names=['trade_date', 'sec'])),
                            OutputDataFormat.MULTI_INDEX_DF,
                            INDEX_INDUSTRY_WEIGHT,
                            pd.DataFrame([1, 2],
                                         index=pd.MultiIndex.from_product([['2010-01-01', '2010-01-02'], ['001']],
                                                                          names=['trade_date', 'industry_code'])
                                         )),
                           (pd.DataFrame([1, 2], index=pd.Index(['2010-01-01', '2010-01-02'], name='trade_date')),

                            OutputDataFormat.PITVOT_TABLE_DF,