Skip to content

Commit

Permalink
Fix importing ABC from collections in Python 3. (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi committed Jun 10, 2020
1 parent 8145740 commit 808294b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
@@ -1,6 +1,7 @@
# Next Release

- [#380](https://github.com/IAMconsortium/pyam/pull/380) Add compatibility with latest matplotlib and py3.8
- [#393](https://github.com/IAMconsortium/pyam/pull/393) Import ABC from collections.abc for Python 3.10 compatibility.

# Release v0.6.0

Expand Down
4 changes: 2 additions & 2 deletions pyam/iiasa.py
@@ -1,4 +1,3 @@
import collections
import json
import logging
import os
Expand All @@ -9,6 +8,7 @@
import numpy as np
import pandas as pd

from collections.abc import Mapping
from pyam.core import IamDataFrame
from pyam.utils import META_IDX, islistable, isstr, pattern_match

Expand Down Expand Up @@ -39,7 +39,7 @@ def _get_token(creds, base_url):
# otherwise read creds and try to login
filecreds = False
try:
if isinstance(creds, collections.Mapping):
if isinstance(creds, Mapping):
user, pw = creds['username'], creds['password']
elif os.path.exists(str(creds)):
with open(str(creds), 'r') as stream:
Expand Down
4 changes: 2 additions & 2 deletions pyam/plotting.py
Expand Up @@ -8,8 +8,8 @@
import numpy as np
import pandas as pd

from collections import defaultdict, Iterable

from collections import defaultdict
from collections.abc import Iterable

from pyam.run_control import run_control
from pyam.utils import requires_package, IAMC_IDX, SORT_IDX, isstr
Expand Down
6 changes: 3 additions & 3 deletions pyam/run_control.py
@@ -1,8 +1,8 @@
import copy
import collections
import os
import yaml

from collections.abc import Mapping
from pyam.utils import isstr

# user-defined defaults for various plot settings
Expand Down Expand Up @@ -40,15 +40,15 @@ def run_control():
def _recursive_update(d, u):
"""recursively update a dictionary d with a dictionary u"""
for k, v in u.items():
if isinstance(v, collections.Mapping):
if isinstance(v, Mapping):
r = _recursive_update(d.get(k, {}), v)
d[k] = r
else:
d[k] = u[k]
return d


class RunControl(collections.Mapping):
class RunControl(Mapping):
"""A thin wrapper around a Python Dictionary to support configuration of
harmonization execution. Input can be provided as dictionaries or YAML
files.
Expand Down
8 changes: 4 additions & 4 deletions pyam/utils.py
Expand Up @@ -3,13 +3,13 @@
import string
import six
import re
import collections
import datetime
import dateutil
import time

import numpy as np
import pandas as pd
from collections.abc import Iterable

try:
import seaborn as sns
Expand Down Expand Up @@ -61,12 +61,12 @@ def isstr(x):

def isscalar(x):
"""Returns True if x is a scalar"""
return not isinstance(x, collections.Iterable) or isstr(x)
return not isinstance(x, Iterable) or isstr(x)


def islistable(x):
"""Returns True if x is a list but not a string"""
return isinstance(x, collections.Iterable) and not isstr(x)
return isinstance(x, Iterable) and not isstr(x)


def write_sheet(writer, name, df, index=False):
Expand Down Expand Up @@ -331,7 +331,7 @@ def pattern_match(data, values, level=None, regexp=False, has_nan=True):
for filtering (str, int, bool)
"""
matches = np.array([False] * len(data))
if not isinstance(values, collections.Iterable) or isstr(values):
if not isinstance(values, Iterable) or isstr(values):
values = [values]

# issue (#40) with string-to-nan comparison, replace nan by empty string
Expand Down

0 comments on commit 808294b

Please sign in to comment.