iiasa / message-ix-models

Tools for the MESSAGEix-GLOBIOM family of models
https://docs.messageix.org/models
Apache License 2.0
17 stars 33 forks source link

Error with collection.ABC.Mapping #63

Closed OFR-IIASA closed 2 years ago

OFR-IIASA commented 2 years ago

When trying to load a module from message-ix-models, the following error occurs (see below)

Traceback (most recent call last):
  File "test_globiom.py", line 3, in <module>
    from message_data.tools.utilities import (
  File "c:\repo\message_data_pr\message_data\tools\__init__.py", line 5, in <module>
    import message_ix_models.util
  File "c:\repo\message-ix-models\message_ix_models\__init__.py", line 5, in <module>
    from message_ix_models.util._logging import setup as setup_logging
  File "c:\repo\message-ix-models\message_ix_models\util\__init__.py", line 13, in <module>
    from .common import (
  File "c:\repo\message-ix-models\message_ix_models\util\common.py", line 78, in <module>
    class MappingAdapter(Adapter):
  File "c:\repo\message-ix-models\message_ix_models\util\common.py", line 102, in MappingAdapter
    def __init__(self, maps: Mapping[str, Sequence[Tuple[str, str]]]):
TypeError: 'ABCMeta' object is not subscriptable

Searching online provides the following solution:

"You should use typing.Mapping instead of collections.abc.Mapping. typing contains many generic versions of various types, which are designed to be used in type hints. According to the mypy documentation, there are some differences between the typing classes and the collections.abc classes, but they're unclear on exactly what those differences are."

Changing to the use of typing.Mapping has resolved the above issue, but no further tests were carried out to see if everything else works as required.

FYI:

ixmp:        3.4.1.dev19+g0c1a143
     0c1a143 (HEAD, upstream/main) Merge pull request #435 from iiasa/feature/dataclass-config
message_ix:  3.4.1.dev72+g2045b07.d20220401
     2045b07 (HEAD, upstream/main) Merge pull request #327 from behnam-zakeri/cleanup-macro
message_ix_models: 2022.3.30
     e0b5fd0 (HEAD, tag: v2022.3.30, upstream/main) Merge pull request #61 from iiasa/release/2022-3-30
message_data: 2020.6.21.dev1232+gb4a961ba
     b4a961ba (HEAD -> issue/356, upstream/issue/356) Resolve issue of incorrect rel_act entry for oil_exp

click:       8.0.3
dask:        2020.12.0
genno:       installed
graphviz:    0.13.2
jpype:       1.2.1
… JVM path:  C:\Program Files\Java\jre1.8.0_231\bin\server\jvm.dll
openpyxl:    3.0.5
pandas:      1.3.5
pint:        0.11
xarray:      0.20.2
yaml:        5.3.1

iam_units:   installed
jupyter:     installed
matplotlib:  3.3.2
plotnine:    0.7.0
pyam:        0.11.0+2.gdecd691
     decd691 (HEAD -> main, origin/main, origin/HEAD) Enable explicit `label` and fix for non-string items in plot legend (#519)

GAMS:        33.1.0

python:      3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS:          Windows
OS-release:  10
machine:     AMD64
processor:   Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder:   little
LC_ALL:      None
LANG:        ZZ
LOCALE:      (None, None)
khaeru commented 2 years ago

Thanks. I noticed and fixed this in the course of #60; see 794e9ce4b329ba3eec4766174462f33968b13587.

I can merge that PR as soon as @gidden gives a final ✅.