Skip to content

Commit

Permalink
Merge pull request #52 from khaeru/hotfix/sel-args
Browse files Browse the repository at this point in the history
Correct use of either_dict_or_kwargs() in AttrSeries.sel()
  • Loading branch information
khaeru authored Nov 23, 2021
2 parents 3bfb54d + 38c8fe8 commit 0e07739
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
- uses: actions/setup-python@v2
# Uncomment and set this to match the "Latest version testable on GitHub
# Actions" in pytest.yaml, if that is not the default used by setup-python
# with:
# python-version: "3.9"
with:
python-version: "3.9"

- name: Cache Python packages
uses: actions/cache@v2
Expand Down
24 changes: 10 additions & 14 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ jobs:
- ubuntu-latest
- windows-latest
python-version:
- "3.6" # Earliest version supported by genno; matches xarray
- "3.7" # Earliest version supported by genno; matches xarray/setup.cfg
- "3.8"
- "3.9" # Latest Python release / latest testable on GitHub Actions

# For development versions of Python, compiled binary wheels are not
# available for some dependencies, e.g. llvmlite, numba, numpy, and/or
# pandas. Compiling these on the job runner requires a more elaborate
# build environment, currently out of scope for genno.
# - "3.10.0-alpha.1" # Development version

exclude:
# This job triggers errors when importing ixmp.testing: no module named
# ixmp.backend. Not critical, since it's upstream.
- os: windows-latest
python-version: "3.6"
- "3.9" # Latest testable on GitHub Actions

# For new releases or development versions of Python, compiled binary
# wheels may not be available for some dependencies, e.g. llvmlite,
# numba, numpy, and/or pandas. Compiling these on the job runner
# requires a more elaborate build environment, currently out of scope
# for genno. Exclude these versions from CI.
# - "3.10" # Latest Python release / latest supported by genno
# - "3.11.0-alpha.2" # Development version

fail-fast: false

Expand Down
7 changes: 5 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ What's new
:backlinks: none
:depth: 1

.. Next release
.. ============
Next release
============

- Fix error messages raised by :meth:`.AttrSerie.sel` on incorrect usage (:pull:`52`).
- :mod:`genno` no longer supports Python 3.6 or earlier, following :mod:`xarray` (:pull:`52`)

v1.8.1 (2021-07-27)
===================
Expand Down
2 changes: 1 addition & 1 deletion genno/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _encode(o):
return json.JSONEncoder().default(o)


@_encode.register(Path) # py3.6 compat: must give the type as an argument
@_encode.register
def _encode_path(o: Path):
return str(o)

Expand Down
2 changes: 1 addition & 1 deletion genno/core/attrseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def rename(self, new_name_or_name_dict):

def sel(self, indexers=None, drop=False, **indexers_kwargs):
"""Like :meth:`xarray.DataArray.sel`."""
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "indexers")
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")

if len(indexers) == 1:
level, key = list(indexers.items())[0]
Expand Down
4 changes: 1 addition & 3 deletions genno/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ def test_foo(caplog):
# the level of the logger for the whole package (parent of the current module)
ctx = caplog.at_level(at_level, logger=__name__.split(".")[0])
else:
# Python 3.6 compatibility: use suppress for nullcontext
nullcontext = getattr(contextlib, "nullcontext", contextlib.suppress)
# ctx does nothing
ctx = nullcontext()
ctx = contextlib.nullcontext()

try:
with ctx:
Expand Down
9 changes: 3 additions & 6 deletions genno/tests/core/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ def _product(a, b):
# Failures without raising an exception
c.add(queue, max_tries=3, fail=logging.INFO)
assert "Failed 3 times to add:" in caplog.messages

# NB the following works in Python >= 3.7, but not 3.6, where it ends ",)"
# assert " with MissingKeyError('foo-3')" in caplog.messages
expr = re.compile(r" with MissingKeyError\('foo-3',?\)")
assert any(expr.match(m) for m in caplog.messages)
assert " with MissingKeyError('foo-3')" in caplog.messages

queue = [((Key("bar", list("abcd")), 10), dict(sums=True))]
added = c.add_queue(queue)
Expand Down Expand Up @@ -682,7 +678,8 @@ def test_units(ureg):
"""Test handling of units within computations."""
c = Computer()

assert isinstance(c.unit_registry, pint.UnitRegistry)
# One of the two classes may be referenced
assert isinstance(c.unit_registry, (pint.UnitRegistry, pint.ApplicationRegistry))

# Create some dummy data
dims = dict(coords=["a b c".split()], dims=["x"])
Expand Down
9 changes: 2 additions & 7 deletions genno/tests/core/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
def test_computationerror(caplog):
ce_none = ComputationError(None)

# Message ends with ',)' on Python 3.6, only ')' on Python 3.7
msg = (
"Exception raised while formatting None:\nAttributeError"
"(\"'NoneType' object has no attribute '__traceback__'\""
"(\"'NoneType' object has no attribute '__traceback__'\")"
)
with assert_logs(caplog, msg):
str(ce_none)


# The TypeError message differs:
# - Python 3.6: "must be str, not float"
# - Python 3.7: "can only concatenate str (not "float") to str"
EXPECTED = re.compile(
r"""computing 'test' using:
Expand All @@ -31,8 +27,7 @@ def test_computationerror(caplog):
Computation traceback:
File "(<ipython-input-\d*-\w+>|[^"]*\.py)", line 4, in fail
'x' \+ 3.4 # Raises TypeError
TypeError: .*str.*float.*
"""
TypeError: can only concatenate str \(not "float"\) to str.*"""
)


Expand Down
2 changes: 1 addition & 1 deletion genno/tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_register(self):
Encoder().default(Bar())

# Register a serializer
@Encoder.register(Bar) # py3.6 compat: must give the type as an argument
@Encoder.register
def _serialize_bar(o: Bar):
return dict(bar=42)

Expand Down
9 changes: 3 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Information Analysis

[options]
packages = genno
python_requires = >=3.6
python_requires = >=3.7
include_package_data = True
install_requires =
dask [array] >= 2.14
Expand All @@ -35,7 +35,7 @@ install_requires =
PyYAML
setuptools >= 41
sparse >= 0.12
xarray
xarray >= 0.17
setup_requires =
setuptools >= 41
setuptools_scm
Expand Down Expand Up @@ -86,9 +86,6 @@ profile = black
max-line-length = 88

[mypy]
# Empty section required as of mypy 0.800;
# see https://github.com/python/mypy/issues/9940

[mypy-dask.*]
ignore_missing_imports = True
[mypy-numpy.*]
Expand Down

0 comments on commit 0e07739

Please sign in to comment.