-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from khaeru/issue/5
Remove ixmp dependency in tests
- Loading branch information
Showing
29 changed files
with
732 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
from .compat.ixmp.reporter import Reporter | ||
from .core import configure | ||
from .core.computer import Computer | ||
from .core.exceptions import ComputationError, KeyExistsError, MissingKeyError | ||
from .core.key import Key | ||
from .core.quantity import Quantity | ||
from .util import RENAME_DIMS | ||
|
||
__all__ = [ | ||
"RENAME_DIMS", | ||
"ComputationError", | ||
"Computer", | ||
"Key", | ||
"KeyExistsError", | ||
"MissingKeyError", | ||
"Quantity", | ||
"Reporter", | ||
"configure", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
from .reporter import Reporter, keys_for_quantity | ||
HAS_IXMP = True | ||
|
||
__all__ = ["Reporter", "keys_for_quantity"] | ||
|
||
HAS_IXMP = True | ||
def configure(path=None, **config): | ||
"""Configure :mod:`genno` globally. | ||
Modifies global variables that affect the behaviour of *all* Reporters and | ||
computations, namely :obj:`.RENAME_DIMS`. | ||
Valid configuration keys—passed as *config* keyword arguments—include: | ||
Other Parameters | ||
---------------- | ||
rename_dims : mapping of str -> str | ||
Update :obj:`.RENAME_DIMS`. | ||
Warns | ||
----- | ||
UserWarning | ||
If *config* contains unrecognized keys. | ||
""" | ||
from genno import core | ||
|
||
from .util import RENAME_DIMS | ||
|
||
core.configure(path, **config) | ||
|
||
# Dimensions to be renamed | ||
RENAME_DIMS.update(config.get("rename_dims", {})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from functools import lru_cache | ||
from typing import Dict | ||
|
||
import pandas as pd | ||
|
||
#: Dimensions to rename when extracting raw data from Scenario objects. | ||
#: Mapping from Scenario dimension name -> preferred dimension name. | ||
RENAME_DIMS: Dict[str, str] = {} | ||
|
||
|
||
def dims_for_qty(data): | ||
"""Return the list of dimensions for *data*. | ||
If *data* is a :class:`pandas.DataFrame`, its columns are processed; | ||
otherwise it must be a list. | ||
genno.RENAME_DIMS is used to rename dimensions. | ||
""" | ||
if isinstance(data, pd.DataFrame): | ||
# List of the dimensions | ||
dims = data.columns.tolist() | ||
else: | ||
dims = list(data) | ||
|
||
# Remove columns containing values or units; dimensions are the remainder | ||
for col in "value", "lvl", "mrg", "unit": | ||
try: | ||
dims.remove(col) | ||
except ValueError: | ||
continue | ||
|
||
# Rename dimensions | ||
return [RENAME_DIMS.get(d, d) for d in dims] | ||
|
||
|
||
@lru_cache(1) | ||
def get_reversed_rename_dims(): | ||
return {v: k for k, v in RENAME_DIMS.items()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.