Skip to content

Commit

Permalink
fix exceptions in File.__getitem__() (h/t @kmulvaney) (#22)
Browse files Browse the repository at this point in the history
* fix exceptions in File.__getitem__() (h/t @kmulvaney)

- commit 310c751 introduced Python 3-specific syntax (raise … from …)
  that broke Python 2. Replace with a method from python-future.

* move raise_from import to pycompat submodule

* fix undeclared encoding in test_gdx.py

* remove an unnecessary Unicode character in File.info()

* complete previous
  • Loading branch information
khaeru authored Sep 26, 2016
1 parent bb1a0ba commit 9c5fb83
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gdx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pandas
import xarray as xr

from .pycompat import install_aliases, filter, range, super, zip
from .pycompat import install_aliases, filter, raise_from, range, super, zip
install_aliases()

from .api import GDX, gdxcc, type_str, vartype_str
Expand Down Expand Up @@ -408,7 +408,7 @@ def info(self, name):
"""Informal string representation of the Symbol with *name*."""
if isinstance(self._state[name], dict):
attrs = self._state[name]['attrs']
return '{} {}({}) {} records: {}'.format(
return '{} {}({}), {} records: {}'.format(
attrs['type_str'], name, ','.join(attrs['domain']),
attrs['records'], attrs['description'])
else:
Expand Down Expand Up @@ -474,4 +474,4 @@ def __getitem__(self, key):
self._load_symbol_data(key)
return super(File, self).__getitem__(key)
else:
raise KeyError(key) from e
raise raise_from(KeyError(key), e)
1 change: 1 addition & 0 deletions gdx/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from builtins import filter, range, object, super, zip
from future.standard_library import install_aliases
from future.utils import raise_from

PY3 = sys.version_info[0] >= 3

Expand Down
2 changes: 1 addition & 1 deletion gdx/test/test_gdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_info1(self, gdxfile):

def test_info2(self, rawgdx):
# Use a File where p1 is guaranteed to not have been loaded:
assert (gdx.File(rawgdx).info('p1') == 'unknown parameter p1(s) 1 '
assert (gdx.File(rawgdx).info('p1') == 'unknown parameter p1(s), 1 '
'records: Example parameter with animal data')

def test_dealias(self, gdxfile):
Expand Down

0 comments on commit 9c5fb83

Please sign in to comment.