14
14
15
15
from message_ix_models .tools .exo_data import ExoDataSource , register_source
16
16
from message_ix_models .util import (
17
+ HAS_MESSAGE_DATA ,
17
18
cached ,
18
- local_data_path ,
19
19
package_data_path ,
20
20
private_data_path ,
21
21
)
30
30
31
31
DIMS = ["COUNTRY" , "PRODUCT" , "TIME" , "FLOW" , "MEASURE" ]
32
32
33
- FWF_COLUMNS = {
34
- "COUNTRY" : (0 , 26 ),
35
- "PRODUCT" : (26 , 32 ),
36
- "TIME" : (32 , 48 ),
37
- "FLOW" : (48 , 64 ),
38
- "MEASURE" : (64 , 68 ),
39
- "Value" : (68 , 100 ),
40
- }
41
-
42
33
#: Subset of columns to load, mapped to returned values.
43
34
CSV_COLUMNS = {
44
35
"COUNTRY" : "node" ,
@@ -225,7 +216,7 @@ def load_data(
225
216
provider : str ,
226
217
edition : str ,
227
218
query_expr = "MEASURE == 'TJ' and TIME >= 1980" ,
228
- base_path = None ,
219
+ path : Optional [ Path ] = None ,
229
220
) -> pd .DataFrame :
230
221
"""Load data from the IEA World Energy Balances.
231
222
@@ -252,15 +243,16 @@ def load_data(
252
243
files = FILES [(provider , edition )]
253
244
254
245
# Identify a location that contains the `files`
255
- if base_path is None :
256
- try :
257
- base_path = private_data_path ("iea" )
258
- assert base_path .joinpath (files [0 ]).exists ()
259
- except AssertionError :
260
- base_path = local_data_path ("iea" )
261
- assert base_path .joinpath (files [0 ]).exists ()
262
-
263
- return iea_web_data_for_query (base_path , * files , query_expr = query_expr )
246
+ if path is None :
247
+ if HAS_MESSAGE_DATA :
248
+ path = private_data_path ("iea" )
249
+ else :
250
+ path = package_data_path ("test" , "iea" )
251
+ log .warning (f"Reading random data from { path } " )
252
+
253
+ assert path .joinpath (files [0 ]).exists ()
254
+
255
+ return iea_web_data_for_query (path , * files , query_expr = query_expr )
264
256
265
257
266
258
def generate_code_lists (
0 commit comments