Skip to content

Commit d71053f

Browse files
committed
Rename .transport.util.region_path_fallback()
Avoid duplicating the name of package .util.path_fallback() with different behaviour.
1 parent 5cd10f0 commit d71053f

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

message_ix_models/model/transport/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MaybeAdaptR11Source(ExoDataSource):
150150
_adapter: Optional[Callable] = None
151151

152152
def __init__(self, source, source_kw):
153-
from .util import path_fallback
153+
from .util import region_path_fallback
154154

155155
# Check that the given measure is supported by the current class
156156
if not source == self.id:
@@ -175,11 +175,11 @@ def __init__(self, source, source_kw):
175175

176176
filename = self.filename[measure]
177177
try:
178-
self.path = path_fallback(nodes, filename)
178+
self.path = region_path_fallback(nodes, filename)
179179
self._repr = f"Load {self.path}"
180180
except FileNotFoundError:
181181
log.info(f"Fall back to R11 data for {self.measure}")
182-
self.path = path_fallback("R11", filename)
182+
self.path = region_path_fallback("R11", filename)
183183

184184
# Identify an adapter that can convert data from R11 to `nodes`
185185
self._adapter = {"R12": adapt_R11_R12, "R14": adapt_R11_R14}.get(nodes)

message_ix_models/model/transport/emission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from message_ix_models.util import package_data_path
1313

14-
from .util import path_fallback
14+
from .util import region_path_fallback
1515

1616
if TYPE_CHECKING:
1717
from genno.types import AnyQuantity
@@ -26,7 +26,7 @@ def get_emissions_data(context: "Context") -> "ParameterData":
2626
"""Load emissions data from a file."""
2727

2828
fn = f"{context.transport.data_source.emissions}-emission_factor.csv"
29-
qty = load_file(path_fallback(context, "emi", fn))
29+
qty = load_file(region_path_fallback(context, "emi", fn))
3030

3131
return dict(emission_factor=qty.to_dataframe())
3232

message_ix_models/model/transport/structure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from message_ix_models.model.structure import generate_set_elements, get_region_codes
1212
from message_ix_models.util import load_package_data, package_data_path
1313

14-
from .util import path_fallback
14+
from .util import region_path_fallback
1515

1616
#: Template for disutility technologies.
1717
TEMPLATE = Code(
@@ -80,7 +80,7 @@ def make_spec(regions: str) -> Spec:
8080

8181
# Load and store the data from the YAML file: either in a subdirectory for
8282
# context.model.regions, or the top-level data directory
83-
path = path_fallback(regions, fn).relative_to(package_data_path())
83+
path = region_path_fallback(regions, fn).relative_to(package_data_path())
8484
tmp[name] = load_package_data(*path.parts)
8585

8686
# Merge contents of technology.yaml into set.yaml

message_ix_models/model/transport/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def has_input_commodity(technology: "Code", commodity: str) -> bool:
3232
return False
3333

3434

35-
def path_fallback(context_or_regions: Union[Context, str], *parts) -> Path:
35+
def region_path_fallback(context_or_regions: Union[Context, str], *parts) -> Path:
3636
"""Return a :class:`.Path` constructed from `parts`.
3737
3838
If ``context.model.regions`` (or a string value as the first argument) is defined

message_ix_models/util/sdmx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ def add_tasks(
367367
) -> tuple["KeyLike", ...]:
368368
"""Prepare `c` to read data from a file at :attr:`.path`."""
369369
# TODO Use a package-wide utility or a callback
370-
from message_ix_models.model.transport.util import path_fallback
370+
from message_ix_models.model.transport.util import region_path_fallback
371371

372372
# Identify the path
373373
try:
374-
path = path_fallback(context, self.path)
374+
path = region_path_fallback(context, self.path)
375375
except FileNotFoundError:
376376
if self.required:
377377
raise

0 commit comments

Comments
 (0)