Skip to content

Commit c6950f5

Browse files
committed
DOC: Update ArrayProxy docstrings
1 parent ad35340 commit c6950f5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

nibabel/arrayproxy.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, file_like, spec, mmap=True):
7878
File-like object or filename. If file-like object, should implement
7979
at least ``read`` and ``seek``.
8080
spec : object or tuple
81-
Tuple must have length 2-5, with the following fields:
81+
Tuple must have length 2-5, with the following values.
8282
- shape : tuple
8383
tuple of ints describing shape of data
8484
- storage_dtype : dtype specifier
@@ -90,7 +90,7 @@ def __init__(self, file_like, spec, mmap=True):
9090
- slope : float
9191
Scaling factor for resulting data (default: 1.0)
9292
- inter : float
93-
Intercept for rescaled dadta (default: 0.0)
93+
Intercept for rescaled data (default: 0.0)
9494
OR
9595
Header object implementing ``get_data_shape``, ``get_data_dtype``,
9696
``get_data_offset``, ``get_slope_inter``
@@ -188,6 +188,11 @@ def __getitem__(self, slicer):
188188
return apply_read_scaling(raw_data, self._slope, self._inter)
189189

190190
def reshape(self, shape):
191+
''' Return an ArrayProxy with a new shape, without modifying data
192+
193+
``array_proxy.reshape(shape)`` is equivalent to
194+
``np.reshape(array_proxy, shape)``
195+
'''
191196
size = np.prod(self._shape)
192197
if np.prod(shape) != size:
193198
raise ValueError("cannot reshape array of size {:d} into shape "

nibabel/tests/test_arrayproxy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,22 @@ def test_tuplespec():
9090
arr = np.arange(24, dtype=dtype).reshape(shape)
9191
bio.seek(16)
9292
bio.write(arr.tostring(order='F'))
93+
# Create equivalent header and tuple specs
9394
hdr = FunkyHeader(shape)
9495
tuple_spec = (hdr.get_data_shape(), hdr.get_data_dtype(),
9596
hdr.get_data_offset(), 1., 0.)
9697
ap_header = ArrayProxy(bio, hdr)
9798
ap_tuple = ArrayProxy(bio, tuple_spec)
99+
# Header and tuple specs produce identical behavior
98100
for prop in ('shape', 'dtype', 'offset', 'slope', 'inter', 'is_proxy'):
99101
assert_equal(getattr(ap_header, prop), getattr(ap_tuple, prop))
100102
for method, args in (('get_unscaled', ()), ('__array__', ()),
101103
('__getitem__', ((0, 2, 1), ))
102104
):
103105
assert_array_equal(getattr(ap_header, method)(*args),
104106
getattr(ap_tuple, method)(*args))
107+
# Tuple-defined ArrayProxies have no header to store
108+
assert_true(ap_tuple.header is None)
105109

106110

107111
def write_raw_data(arr, hdr, fileobj):

0 commit comments

Comments
 (0)