Beispiel #1
0
    def test__import_vd(self):

        fo = {
            "file": TestToCERO_FileObj._dd + "test__import_vd.VD",
            "date_col": 3,
            "val_col": 8
        }

        fo = ToCERO._FileObj(fo)
        df = fo._import_vd()
        df.columns.set_names([None], inplace=True)
        df = df.astype(pd.np.float32)

        test_df = pd.DataFrame.from_dict(
            {
                ("VAR_Act", "-", "FT_COMELC", "ACT", "2015", "PD", "-"): [
                    0.740833333333336, 0.740833333333336, 0.8005115537522,
                    0.829127920241238
                ]
            },
            orient="index",
            dtype=pd.np.float32)
        test_df.columns = pd.Index([2015, 2016, 2020, 2025])
        test_df.sort_index(inplace=True)

        self.assertTrue(test_df.equals(df))

        fo = {
            "file": TestToCERO_FileObj._dd + "test__import_vd.VD",
            "date_col": 3,
            "val_col": 8,
            "default_year": 2018
        }

        fo = ToCERO._FileObj(fo)
        df = fo._import_vd()
        df.columns.set_names([None], inplace=True)
        df = df.astype(pd.np.float32)
        df.sort_index(inplace=True)

        test_df = pd.DataFrame(data=[
            [
                0.740833333333336, 0.740833333333336, pd.np.nan,
                0.8005115537522, 0.829127920241238
            ],
            [pd.np.nan, pd.np.nan, 1.39891653080538, pd.np.nan, pd.np.nan],
            [pd.np.nan, pd.np.nan, 19.6047685777802, pd.np.nan, pd.np.nan],
            [pd.np.nan, pd.np.nan, 31516.8951973493, pd.np.nan, pd.np.nan],
        ],
                               columns=[2015, 2016, 2018, 2020, 2025],
                               dtype=pd.np.float32)
        test_df.index = CERO.create_cero_index([
            ("VAR_Act", "-", "FT_COMELC", "ACT", "2015", "PD", "-"),
            ("Cost_Salv", "-", "EN_WinONS-26", "ADE", "2040", "-", "-"),
            ("Cost_NPV", "-", "EE_StmTurb009", "CQ", "-", "-", "ACT"),
            ("Reg_irec", "-", "-", "WA", "-", "-", "-"),
        ])
        test_df.sort_index(inplace=True)
        self.assertTrue(test_df.equals(df))
Beispiel #2
0
    def test_csv_orientation(self):

        tc = ToCERO._FileObj(
            {"file": TestToCERO_FileObj._dd + "test_csv_orientation.csv"})

        with self.assertRaises(TypeError):
            df = tc._import_file()

        tc = ToCERO._FileObj({
            "file": TestToCERO_FileObj._dd + "test_csv_orientation.csv",
            "orientation": "cols"
        })

        df = tc._import_file()

        test_df = pd.DataFrame(data=[[1, 2], [3, 4]],
                               columns=[2016, 2017],
                               dtype=pd.np.float32)
        test_df.index = CERO.create_cero_index(["A", "B"])
        test_df.sort_index(inplace=True)

        self.assertTrue(df.equals(test_df))
Beispiel #3
0
    def test__import_gdx(self):

        fo = {
            "file": TestToCERO_FileObj._dd + "test__import_gdx.gdx",
            "symbols": {
                "name": "L_EXPORT",
                "date_col": 2
            }
        }
        fo = ToCERO._FileObj(fo)
        df = fo._import_gdx()

        with open(TestToCERO_FileObj._dd + "test__import_gdx.pickle",
                  "rb") as f:
            test_df = pickle.load(f)

        self.assertTrue(df.equals(test_df))
Beispiel #4
0
    def test_har_repetitive_sets(self):

        fo = ToCERO._FileObj({
            "file":
            "test.har",
            "search_paths":
            TestToCERO_FileObj._dd,
            "head_arrs": [{
                "name": "ARR7",
                "default_year": 2018
            }]
        })
        cero = fo.import_file_as_cero()

        df = DataTools.get_test_data(TestToCERO_FileObj._dd +
                                     "test_har_repetitive_sets.pickle")

        self.assertTrue(cero.equals(df))