def test_remove_empty_lines(self): data = [ ["SIMPLICITY", "ETH", 2014, 1.0], [], ["SIMPLICITY", "ETH", 2015, 1.03], [], ] df = pd.DataFrame(data=data, columns=["REGION", "FUEL", "YEAR", "VALUE"]) parameters = {"AccumulatedAnnualDemand": df} reader = ReadMemory(parameters) actual, _ = reader.read() expected = { "AccumulatedAnnualDemand": pd.DataFrame( data=[ ["SIMPLICITY", "ETH", 2014, 1.0], ["SIMPLICITY", "ETH", 2015, 1.03], ], columns=["REGION", "FUEL", "YEAR", "VALUE"], ).astype({ "REGION": str, "FUEL": str, "YEAR": int, "VALUE": float }).set_index(["REGION", "FUEL", "YEAR"]) } assert "AccumulatedAnnualDemand" in actual.keys() pd.testing.assert_frame_equal(actual["AccumulatedAnnualDemand"], expected["AccumulatedAnnualDemand"])
def test_index_dtypes_available(self): reader = ReadMemory({}) config = reader._input_config assert "index_dtypes" in config["AccumulatedAnnualDemand"].keys() actual = config["AccumulatedAnnualDemand"]["index_dtypes"] assert actual == { "REGION": "str", "FUEL": "str", "YEAR": "int", "VALUE": "float", }
def test_read_memory(self): data = [ ["SIMPLICITY", "ETH", 2014, 1.0], ["SIMPLICITY", "RAWSUG", 2014, 0.5], ["SIMPLICITY", "ETH", 2015, 1.03], ["SIMPLICITY", "RAWSUG", 2015, 0.51], ] df = pd.DataFrame(data=data, columns=["REGION", "FUEL", "YEAR", "VALUE"]) parameters = {"AccumulatedAnnualDemand": df} actual, default_values = ReadMemory(parameters).read() expected = { "AccumulatedAnnualDemand": pd.DataFrame(data=data, columns=["REGION", "FUEL", "YEAR", "VALUE" ]).set_index(["REGION", "FUEL", "YEAR"]) } assert "AccumulatedAnnualDemand" in actual.keys() pd.testing.assert_frame_equal(actual["AccumulatedAnnualDemand"], expected["AccumulatedAnnualDemand"])