Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #136 from pelson/v0.9.1
Browse files Browse the repository at this point in the history
Fixed trailing Ellipsis handling with numpy arrays.
  • Loading branch information
rhattersley committed Mar 25, 2015
2 parents 38ddaaf + 5f104c3 commit 08f6602
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions biggus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import numpy.ma as ma


__version__ = '0.9.0'
__version__ = '0.9.1'


_SCALAR_KEY_TYPES = (int, np.integer)
Expand Down Expand Up @@ -2619,9 +2619,10 @@ def _full_keys(keys, ndim):
# Numpy allows an extra dimension to be an Ellipsis, we remove it here
# if Ellipsis is in keys, if this doesn't trigger we will raise an
# IndexError.
if n_keys_non_newaxis - 1 >= ndim and Ellipsis in keys:
is_ellipsis = [key is Ellipsis for key in keys]
if n_keys_non_newaxis - 1 >= ndim and any(is_ellipsis):
# Remove the left-most Ellipsis, as numpy does.
keys.remove(Ellipsis)
keys.pop(is_ellipsis.index(True))
n_keys_non_newaxis -= 1

if n_keys_non_newaxis > ndim:
Expand Down
7 changes: 6 additions & 1 deletion biggus/tests/unit/test__full_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def nslice(self, n):

def assertFullSlice(self, keys, ndim, expected):
result = _full_keys(keys, ndim)
self.assertEqual(result, tuple(expected))
assert_array_equal(result, tuple(expected))

# Now check that this is actually the numpy behaviour.
a = np.empty(range(7, 7 + ndim), dtype=np.bool)
Expand Down Expand Up @@ -69,6 +69,11 @@ def test_new_axis(self):
self.assertFullSlice((np.newaxis, ), 2,
[np.newaxis, slice(None), slice(None)])

def test_numpy_and_ellipsis_1d(self):
# The key is that Ellipsis needs to be stripped off the keys.
self.assertFullSlice((np.array([0, 4, 5, 2]), Ellipsis), 1,
[np.array([0, 4, 5, 2])])

def test_new_axis_lh_and_rh(self):
self.assertFullSlice((np.newaxis, Ellipsis, None, np.newaxis), 2,
[None, slice(None), slice(None), None, None])
Expand Down
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@

# General information about the project.
project = u'Biggus'
copyright = u'2014, Richard Hattersley'
copyright = 'British Crown Copyright 2014 - 2015, Met Office'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.9.0'
version = '0.9.1'
# The full version, including alpha/beta/rc tags.
release = '0.9.0'
release = '0.9.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run(self):

setup(
name='Biggus',
version='0.9.0',
version='0.9.1',
url='https://github.com/SciTools/biggus',
author='Richard Hattersley',
author_email='[email protected]',
Expand Down

0 comments on commit 08f6602

Please sign in to comment.