diff --git a/pypsa_validation_processing/statistics_functions.py b/pypsa_validation_processing/statistics_functions.py index 007cfe3..70fc6cf 100644 --- a/pypsa_validation_processing/statistics_functions.py +++ b/pypsa_validation_processing/statistics_functions.py @@ -87,24 +87,19 @@ def Final_Energy_by_Sector__Transportation( Notes ----- - The actual extraction of transportation final energy from the network - collection will be implemented by the user. A typical call would be:: - - network_collection.statistics.energy_balance( - comps=["Load"], carrier="transport" - ) - - The current implementation returns a dummy value of ``0.0 MWh`` for the - year 2020 so that the end-to-end workflow can be tested. + Includes all transportation-relevant carriers for component Load. Vehicle to Grid + does not need to be evaluated, as evaluation is restricted to Load-Components only. """ # sum over all transportation-relevant sectors - 2 different units involved. - result = ( + res = ( n.statistics.energy_balance( carrier=[ "land transport EV", "land transport fuel cell", + "land transport oil", "kerosene for aviation", "shipping methanol", + "shipping oil", ], components="Load", groupby=["carrier", "unit", "country"], @@ -113,4 +108,4 @@ def Final_Energy_by_Sector__Transportation( .groupby(["country", "unit"]) .sum() ) - return result + return res diff --git a/tests/test_statistics_functions.py b/tests/test_statistics_functions.py index bf16c45..89f5803 100644 --- a/tests/test_statistics_functions.py +++ b/tests/test_statistics_functions.py @@ -21,16 +21,16 @@ class TestFinalEnergyByCarrierElectricity: """Test suite for Final_Energy_by_Carrier__Electricity function.""" - def test_returns_dataframe(self, mock_network: MockPyPSANetwork): - """Test that the function returns a pandas DataFrame or Series.""" + def test_returns_series(self, mock_network: MockPyPSANetwork): + """Test that the function returns a pandas Series.""" result = Final_Energy_by_Carrier__Electricity(mock_network) - assert isinstance(result, (pd.DataFrame, pd.Series)) + assert isinstance(result, pd.Series) - def test_has_country_and_unit_index(self, mock_network: MockPyPSANetwork): - """Test that result has country and unit in the index.""" + def test_has_country_and_unit_multiindex(self, mock_network: MockPyPSANetwork): + """Test that result has MultiIndex with country and unit levels.""" result = Final_Energy_by_Carrier__Electricity(mock_network) - assert "country" in result.index.names - assert "unit" in result.index.names + assert isinstance(result.index, pd.MultiIndex) + assert result.index.names == ["country", "unit"] def test_not_empty(self, mock_network: MockPyPSANetwork): """Test that result is not empty.""" @@ -53,7 +53,9 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection) """Test processing multiple networks from collection.""" for network in mock_network_collection: result = Final_Energy_by_Carrier__Electricity(network) - assert isinstance(result, (pd.DataFrame, pd.Series)) + assert isinstance(result, pd.Series) + assert isinstance(result.index, pd.MultiIndex) + assert result.index.names == ["country", "unit"] assert len(result) > 0 @@ -65,16 +67,16 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection) class TestFinalEnergyBySectorTransportation: """Test suite for Final_Energy_by_Sector__Transportation function.""" - def test_returns_dataframe(self, mock_network: MockPyPSANetwork): - """Test that the function returns a pandas DataFrame or Series.""" + def test_returns_series(self, mock_network: MockPyPSANetwork): + """Test that the function returns a pandas Series.""" result = Final_Energy_by_Sector__Transportation(mock_network) - assert isinstance(result, (pd.DataFrame, pd.Series)) + assert isinstance(result, pd.Series) - def test_has_country_and_unit_index(self, mock_network: MockPyPSANetwork): - """Test that result has country and unit in the index.""" + def test_has_country_and_unit_multiindex(self, mock_network: MockPyPSANetwork): + """Test that result has MultiIndex with country and unit levels.""" result = Final_Energy_by_Sector__Transportation(mock_network) - assert "country" in result.index.names - assert "unit" in result.index.names + assert isinstance(result.index, pd.MultiIndex) + assert result.index.names == ["country", "unit"] def test_not_empty(self, mock_network: MockPyPSANetwork): """Test that result is not empty.""" @@ -97,5 +99,7 @@ def test_multiple_networks(self, mock_network_collection: MockNetworkCollection) """Test processing multiple networks from collection.""" for network in mock_network_collection: result = Final_Energy_by_Sector__Transportation(network) - assert isinstance(result, (pd.DataFrame, pd.Series)) + assert isinstance(result, pd.Series) + assert isinstance(result.index, pd.MultiIndex) + assert result.index.names == ["country", "unit"] assert len(result) > 0