Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions biggus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, concrete, keys=()):
# concrete must have:
# dtype
# shape
self._concrete = concrete
self.concrete = concrete
if not isinstance(keys, tuple):
keys = (keys,)
assert len(keys) <= len(concrete.shape)
Expand All @@ -147,18 +147,18 @@ def __init__(self, concrete, keys=()):

@property
def dtype(self):
return self._concrete.dtype
return self.concrete.dtype

@property
def fill_value(self):
fill_value = getattr(self._concrete, 'fill_value', None)
fill_value = getattr(self.concrete, 'fill_value', None)
if fill_value is None:
fill_value = Array.fill_value.fget(self)
return fill_value

@property
def shape(self):
shape = _sliced_shape(self._concrete.shape, self._keys)
shape = _sliced_shape(self.concrete.shape, self._keys)
return shape

def _cleanup_new_key(self, key, size, axis):
Expand Down Expand Up @@ -229,7 +229,7 @@ def __getitem__(self, keys):
raise IndexError('too many keys')

result_keys = []
shape = list(self._concrete.shape)
shape = list(self.concrete.shape)
src_keys = list(self._keys or [])
new_keys = list(keys)

Expand Down Expand Up @@ -271,7 +271,7 @@ def __getitem__(self, keys):
result_keys.append(result_key)
axis += 1

return type(self)(self._concrete, tuple(result_keys))
return type(self)(self.concrete, tuple(result_keys))

@abstractmethod
def _apply_keys(self):
Expand Down Expand Up @@ -335,19 +335,19 @@ def _apply_keys(self):
cut_keys = list(keys)
for i, key in tuple_keys:
cut_keys[i] = slice(None)
array = self._concrete[tuple(cut_keys)]
array = self.concrete[tuple(cut_keys)]
is_scalar = [isinstance(key, int) for key in cut_keys]
dimensions -= np.cumsum(is_scalar)
else:
# Use ellipsis indexing to ensure we have a real ndarray
# instance to work with. (Otherwise self._concrete would
# instance to work with. (Otherwise self.concrete would
# need to implement `take` or `__array__`.)
array = self._concrete[...]
array = self.concrete[...]
# ... and then do each tuple in turn.
for i, key in tuple_keys:
array = np.take(array, key, axis=dimensions[i])
else:
array = self._concrete.__getitem__(keys)
array = self.concrete.__getitem__(keys)
return array


Expand All @@ -374,7 +374,7 @@ class OrthoArrayAdapter(_ArrayAdapter):

"""
def _apply_keys(self):
array = self._concrete.__getitem__(self._keys)
array = self.concrete.__getitem__(self._keys)
return array


Expand Down
17 changes: 17 additions & 0 deletions biggus/tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# (C) British Crown Copyright 2014, Met Office
#
# This file is part of Biggus.
#
# Biggus is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Biggus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Biggus. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for biggus."""
39 changes: 39 additions & 0 deletions biggus/tests/unit/test__ArrayAdapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# (C) British Crown Copyright 2014, Met Office
#
# This file is part of Biggus.
#
# Biggus is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Biggus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Biggus. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for `biggus._ArrayAdapter`."""

import unittest

from biggus import _ArrayAdapter


class Test___init__(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there are 3 (count'em!) underscores here.
It isn't really a full init test, but only tests the '.concrete' aspect, so arguably it should be called "Test___init____concrete".
( as in "Test_/name_of_public_method/__/aspect_of_method" --> "Test_/__init__/__/concrete". )

In fact, a good job this has been renamed, or it would be "Test___init_____concrete".
Five in a row -- could this be a record ?? ;-)

def test_concrete(self):
class FakeConcrete(object):
shape = ()

class FakeAdapter(_ArrayAdapter):
def _apply_keys(self):
pass

concrete = FakeConcrete()
array = FakeAdapter(concrete)
self.assertIs(array.concrete, concrete)


if __name__ == '__main__':
unittest.main()