Skip to content

Commit 0433dd4

Browse files
committed
better docstrings in various functions & methods
1 parent 261e10e commit 0433dd4

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

larray/core/array.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def concat(arrays, axis=0, dtype=None):
251251
arrays : tuple of LArray
252252
Arrays to concatenate.
253253
axis : axis reference (int, str or Axis), optional
254-
Axis along which to concatenate. Defaults to the first axis.
254+
Axis along which to concatenate. All arrays must have that axis. Defaults to the first axis.
255255
dtype : dtype, optional
256256
Result data type. Defaults to the "closest" type which can hold all arrays types without loss of information.
257257
@@ -384,7 +384,7 @@ def __setitem__(self, key, value):
384384
# TODO: rename to LArrayIndexPointsIndexer or something like that
385385
class LArrayPositionalPointsIndexer(object):
386386
"""
387-
the closer to numpy indexing we get, but not 100% the same.
387+
the closest to numpy indexing we get, but not 100% the same.
388388
"""
389389
def __init__(self, array):
390390
self.array = array
@@ -5485,15 +5485,15 @@ def divnot0(self, other):
54855485
# XXX: rename/change to "add_axes" ?
54865486
# TODO: add a flag copy=True to force a new array.
54875487
def expand(self, target_axes=None, out=None, readonly=False):
5488-
"""Expands array to target_axes.
5488+
r"""Expands array to target_axes.
54895489
54905490
Target axes will be added to array if not present.
54915491
In most cases this function is not needed because LArray can do operations with arrays having different
54925492
(compatible) axes.
54935493
54945494
Parameters
54955495
----------
5496-
target_axes : list of Axis or AxisCollection, optional
5496+
target_axes : string, list of Axis or AxisCollection, optional
54975497
Self can contain axes not present in `target_axes`.
54985498
The result axes will be: [self.axes not in target_axes] + target_axes
54995499
out : LArray, optional
@@ -5513,22 +5513,37 @@ def expand(self, target_axes=None, out=None, readonly=False):
55135513
>>> b = Axis('b=b1,b2')
55145514
>>> arr = ndtest([a, b])
55155515
>>> arr
5516-
a\\b b1 b2
5516+
a\b b1 b2
55175517
a1 0 1
55185518
a2 2 3
5519+
5520+
Adding one or several axes will append the new axes at the end
5521+
55195522
>>> c = Axis('c=c1,c2')
5523+
>>> arr.expand(c)
5524+
a b\c c1 c2
5525+
a1 b1 0 0
5526+
a1 b2 1 1
5527+
a2 b1 2 2
5528+
a2 b2 3 3
5529+
5530+
If you want to new axes to be inserted in a particular order, you have to give that order
5531+
55205532
>>> arr.expand([a, c, b])
5521-
a c\\b b1 b2
5533+
a c\b b1 b2
5534+
a1 c1 0 1
5535+
a1 c2 0 1
5536+
a2 c1 2 3
5537+
a2 c2 2 3
5538+
5539+
But it is enough to list only the added axes and the axes after them:
5540+
5541+
>>> arr.expand([c, b])
5542+
a c\b b1 b2
55225543
a1 c1 0 1
55235544
a1 c2 0 1
55245545
a2 c1 2 3
55255546
a2 c2 2 3
5526-
>>> arr.expand([b, c])
5527-
a b\\c c1 c2
5528-
a1 b1 0 0
5529-
a1 b2 1 1
5530-
a2 b1 2 2
5531-
a2 b2 3 3
55325547
"""
55335548
if sum([target_axes is not None, out is not None]) != 1:
55345549
raise ValueError("exactly one of either `target_axes` or `out` must be defined (not both)")
@@ -6767,8 +6782,8 @@ def shift(self, axis, n=1):
67676782
----------
67686783
axis : int, str or Axis
67696784
Axis for which we want to perform the shift.
6770-
n : int
6771-
Number of cells to shift.
6785+
n : int, optional
6786+
Number of cells to shift. Defaults to 1.
67726787
67736788
Returns
67746789
-------
@@ -8275,7 +8290,7 @@ def stack(elements=None, axis=None, title=None, meta=None, **kwargs):
82758290
Returns
82768291
-------
82778292
LArray
8278-
A single array combining arrays.
8293+
A single array combining arrays. The new (stacked) axes will be the last axes of the new array.
82798294
82808295
Examples
82818296
--------

larray/core/metadata.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def __repr__(self):
8989

9090
else:
9191
class AttributeDict(OrderedDict):
92-
9392
def __getattr__(self, key):
9493
try:
9594
return self[key]
@@ -124,7 +123,7 @@ class Metadata(AttributeDict):
124123
>>> # Python 2 or <= 3.5
125124
>>> arr = ndtest((3, 3), meta=[('title', 'the title'), ('author', 'John Smith')])
126125
>>> # Python 3.6+
127-
>>> arr = ndtest((3, 3), meta=Metadata(title = 'the title', author = 'John Smith')) # doctest: +SKIP
126+
>>> arr = ndtest((3, 3), meta=Metadata(title='the title', author='John Smith')) # doctest: +SKIP
128127
129128
Add metadata after array initialization
130129
@@ -143,7 +142,6 @@ class Metadata(AttributeDict):
143142
144143
>>> del arr.meta.creation_date
145144
"""
146-
147145
# TODO: use LArray.from_dict once ready (issue 581)
148146
def __larray__(self):
149147
from larray.core.array import LArray

0 commit comments

Comments
 (0)