From 120d050862c58c8da363d127ae3337b1980adfeb Mon Sep 17 00:00:00 2001 From: Alix Damman Date: Wed, 19 Jun 2019 14:57:02 +0200 Subject: [PATCH] fix #477 : use raw docstrings (to avoid having to escape \) --- larray/core/array.py | 668 +++++++++++++++++++------------------- larray/core/axis.py | 126 +++---- larray/core/group.py | 70 ++-- larray/core/metadata.py | 2 +- larray/core/session.py | 58 ++-- larray/example.py | 4 +- larray/extra/ipfp.py | 8 +- larray/inout/common.py | 20 +- larray/inout/csv.py | 2 +- larray/inout/excel.py | 4 +- larray/inout/hdf.py | 6 +- larray/inout/misc.py | 20 +- larray/inout/pandas.py | 6 +- larray/inout/sas.py | 2 +- larray/inout/session.py | 2 +- larray/inout/xw_excel.py | 24 +- larray/util/options.py | 2 +- larray/viewer/__init__.py | 6 +- 18 files changed, 515 insertions(+), 515 deletions(-) diff --git a/larray/core/array.py b/larray/core/array.py index c2b3efb58..35bf25032 100644 --- a/larray/core/array.py +++ b/larray/core/array.py @@ -68,7 +68,7 @@ def all(values, axis=None): - """ + r""" Test whether all array elements along a given axis evaluate to True. See Also @@ -82,7 +82,7 @@ def all(values, axis=None): def any(values, axis=None): - """ + r""" Test whether any array elements along a given axis evaluate to True. See Also @@ -97,7 +97,7 @@ def any(values, axis=None): # commutative modulo float precision errors def sum(array, *args, **kwargs): - """ + r""" Sum of array elements. See Also @@ -115,7 +115,7 @@ def sum(array, *args, **kwargs): def prod(array, *args, **kwargs): - """ + r""" Product of array elements. See Also @@ -126,7 +126,7 @@ def prod(array, *args, **kwargs): def cumsum(array, *args, **kwargs): - """ + r""" Returns the cumulative sum of array elements. See Also @@ -137,7 +137,7 @@ def cumsum(array, *args, **kwargs): def cumprod(array, *args, **kwargs): - """ + r""" Returns the cumulative product of array elements. See Also @@ -148,7 +148,7 @@ def cumprod(array, *args, **kwargs): def min(array, *args, **kwargs): - """ + r""" Minimum of array elements. See Also @@ -162,7 +162,7 @@ def min(array, *args, **kwargs): def max(array, *args, **kwargs): - """ + r""" Maximum of array elements. See Also @@ -176,7 +176,7 @@ def max(array, *args, **kwargs): def mean(array, *args, **kwargs): - """ + r""" Computes the arithmetic mean. See Also @@ -187,7 +187,7 @@ def mean(array, *args, **kwargs): def median(array, *args, **kwargs): - """ + r""" Computes the median. See Also @@ -198,7 +198,7 @@ def median(array, *args, **kwargs): def percentile(array, *args, **kwargs): - """ + r""" Computes the qth percentile of the data along the specified axis. See Also @@ -210,7 +210,7 @@ def percentile(array, *args, **kwargs): # not commutative def ptp(array, *args, **kwargs): - """ + r""" Returns the range of values (maximum - minimum). See Also @@ -221,7 +221,7 @@ def ptp(array, *args, **kwargs): def var(array, *args, **kwargs): - """ + r""" Computes the variance. See Also @@ -232,7 +232,7 @@ def var(array, *args, **kwargs): def std(array, *args, **kwargs): - """ + r""" Computes the standard deviation. See Also @@ -243,7 +243,7 @@ def std(array, *args, **kwargs): def concat(arrays, axis=0, dtype=None): - """Concatenate arrays along axis + r"""Concatenate arrays along axis Parameters ---------- @@ -262,12 +262,12 @@ def concat(arrays, axis=0, dtype=None): -------- >>> arr1 = ndtest((2, 3)) >>> arr1 - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> arr2 = ndtest('a=a0,a1;b=b3') >>> arr2 - a\\b b3 + a\b b3 a0 0 a1 1 >>> arr3 = ndtest('b=b4,b5') @@ -275,7 +275,7 @@ def concat(arrays, axis=0, dtype=None): b b4 b5 0 1 >>> concat((arr1, arr2, arr3), 'b') - a\\b b0 b1 b2 b3 b4 b5 + a\b b0 b1 b2 b3 b4 b5 a0 0 1 2 0 0 1 a1 3 4 5 1 0 1 """ @@ -342,7 +342,7 @@ def __init__(self, array): self.array = array def _translate_key(self, key): - """ + r""" Translates key into tuple of IGroup, i.e. tuple of collections of labels. """ @@ -657,7 +657,7 @@ def _handle_meta(meta, title): class LArray(ABCLArray): - """ + r""" A LArray object represents a multidimensional, homogeneous array of fixed-size items with labeled axes. The function :func:`aslarray` can be used to convert a NumPy array or Pandas DataFrame into a LArray. @@ -710,7 +710,7 @@ class LArray(ABCLArray): >>> data = np.zeros((len(axes), len(sex), len(time))) >>> LArray(data, axes) - age sex\\time 2007 2008 2009 + age sex\time 2007 2008 2009 10 M 0.0 0.0 0.0 10 F 0.0 0.0 0.0 11 M 0.0 0.0 0.0 @@ -725,7 +725,7 @@ class LArray(ABCLArray): Array creation functions >>> full(axes, 10.0) - age sex\\time 2007 2008 2009 + age sex\time 2007 2008 2009 10 M 10.0 10.0 10.0 10 F 10.0 10.0 10.0 11 M 10.0 10.0 10.0 @@ -736,7 +736,7 @@ class LArray(ABCLArray): >>> arr['F'] = 1.0 >>> arr['M'] = -1.0 >>> arr - age sex\\time 2007 2008 2009 + age sex\time 2007 2008 2009 10 M -1.0 -1.0 -1.0 10 F 1.0 1.0 1.0 11 M -1.0 -1.0 -1.0 @@ -748,7 +748,7 @@ class LArray(ABCLArray): sex M F -1 1 >>> sequence(age, initial=10, inc=bysex) - sex\\age 10 11 12 + sex\age 10 11 12 M 10 9 8 F 10 11 12 """ @@ -792,7 +792,7 @@ def title(self, title): @property def meta(self): - """Returns metadata of the array. + r"""Returns metadata of the array. Returns ------- @@ -891,7 +891,7 @@ def nonzero(self): return tuple(IGroup(axis_key, axis=axis) for axis_key, axis in zip(la_key, self.axes)) def set_axes(self, axes_to_replace=None, new_axis=None, inplace=False, **kwargs): - """ + r""" Replace one, several or all axes of the array. Parameters @@ -922,7 +922,7 @@ def set_axes(self, axes_to_replace=None, new_axis=None, inplace=False, **kwargs) -------- >>> arr = ndtest((2, 3)) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> row = Axis(['r0', 'r1'], 'row') @@ -931,7 +931,7 @@ def set_axes(self, axes_to_replace=None, new_axis=None, inplace=False, **kwargs) Replace one axis (second argument `new_axis` must be provided) >>> arr.set_axes('a', row) - row\\b b0 b1 b2 + row\b b0 b1 b2 r0 0 1 2 r1 3 4 5 @@ -942,19 +942,19 @@ def set_axes(self, axes_to_replace=None, new_axis=None, inplace=False, **kwargs) >>> arr.set_axes([('a', row), ('b', column)]) # doctest: +SKIP >>> # or >>> arr.set_axes({'a': row, 'b': column}) - row\\column c0 c1 c2 + row\column c0 c1 c2 r0 0 1 2 r1 3 4 5 Replace all axes (list of axes or AxisCollection) >>> arr.set_axes([row, column]) - row\\column c0 c1 c2 + row\column c0 c1 c2 r0 0 1 2 r1 3 4 5 >>> arr2 = ndtest([row, column]) >>> arr.set_axes(arr2.axes) - row\\column c0 c1 c2 + row\column c0 c1 c2 r0 0 1 2 r1 3 4 5 """ @@ -997,14 +997,14 @@ def _ipython_key_completions_(self): # TODO: the first slice in example below should be documented @lazy_attribute def i(self): - """ + r""" Allows selection of a subset using indices of labels. Examples -------- >>> arr = ndtest((2, 3, 4)) >>> arr - a b\\c c0 c1 c2 c3 + a b\c c0 c1 c2 c3 a0 b0 0 1 2 3 a0 b1 4 5 6 7 a0 b2 8 9 10 11 @@ -1013,7 +1013,7 @@ def i(self): a1 b2 20 21 22 23 >>> arr.i[:, 0:2, [0, 2]] - a b\\c c0 c2 + a b\c c0 c2 a0 b0 0 2 a0 b1 4 6 a1 b0 12 14 @@ -1023,7 +1023,7 @@ def i(self): @lazy_attribute def points(self): - """ + r""" Allows selection of arbitrary items in the array based on their N-dimensional label index. @@ -1031,7 +1031,7 @@ def points(self): -------- >>> arr = ndtest((2, 3, 4)) >>> arr - a b\\c c0 c1 c2 c3 + a b\c c0 c1 c2 c3 a0 b0 0 1 2 3 a0 b1 4 5 6 7 a0 b2 8 9 10 11 @@ -1060,14 +1060,14 @@ def points(self): # (except at the end) @lazy_attribute def ipoints(self): - """ + r""" Allows selection of arbitrary items in the array based on their N-dimensional index. Examples -------- >>> arr = ndtest((2, 3, 4)) >>> arr - a b\\c c0 c1 c2 c3 + a b\c c0 c1 c2 c3 a0 b0 0 1 2 3 a0 b1 4 5 6 7 a0 b2 8 9 10 11 @@ -1092,7 +1092,7 @@ def ipoints(self): return LArrayPositionalPointsIndexer(self) def to_frame(self, fold_last_axis_name=False, dropna=None): - """ + r""" Converts LArray into Pandas DataFrame. Parameters @@ -1100,6 +1100,7 @@ def to_frame(self, fold_last_axis_name=False, dropna=None): fold_last_axis_name : bool, optional Defaults to False. dropna : {'any', 'all', None}, optional + * any : if any NA values are present, drop that label * all : if all values are NA, drop that label * None by default. @@ -1117,7 +1118,7 @@ def to_frame(self, fold_last_axis_name=False, dropna=None): -------- >>> arr = ndtest((2, 2, 2)) >>> arr - a b\\c c0 c1 + a b\c c0 c1 a0 b0 0 1 a0 b1 2 3 a1 b0 4 5 @@ -1131,7 +1132,7 @@ def to_frame(self, fold_last_axis_name=False, dropna=None): b1 6 7 >>> arr.to_frame(fold_last_axis_name=True) # doctest: +NORMALIZE_WHITESPACE c0 c1 - a b\\c + a b\c a0 b0 0 1 b1 2 3 a1 b0 4 5 @@ -1163,7 +1164,7 @@ def to_frame(self, fold_last_axis_name=False, dropna=None): df = property(to_frame) def to_series(self, name=None, dropna=False): - """ + r""" Converts LArray into Pandas Series. Parameters @@ -1186,7 +1187,7 @@ def to_series(self, name=None, dropna=False): -------- >>> arr = ndtest((2, 3), dtype=float) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.0 1.0 2.0 a1 3.0 4.0 5.0 >>> arr.to_series() # doctest: +NORMALIZE_WHITESPACE @@ -1215,7 +1216,7 @@ def to_series(self, name=None, dropna=False): >>> arr['b1'] = nan >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.0 nan 2.0 a1 3.0 nan 5.0 >>> arr.to_series(dropna=True) # doctest: +NORMALIZE_WHITESPACE @@ -1241,7 +1242,7 @@ def to_series(self, name=None, dropna=False): series = property(to_series) def describe(self, *args, **kwargs): - """ + r""" Descriptive summary statistics, excluding NaN values. By default, it includes the number of non-NaN values, the mean, standard deviation, minimum, maximum and @@ -1358,7 +1359,7 @@ def describe_by(self, *args, **kwargs): # return np.ndarray.__array_prepare__(self.data, arr, context) def __array_wrap__(self, out_arr, context=None): - """ + r""" Called after numpy ufuncs. This is never called during our wrapped ufuncs, but if somebody uses raw numpy function, this works in some cases. @@ -1374,7 +1375,7 @@ def __bool__(self): # TODO: either support a list (of axes names) as first argument here (and set_labels) # or don't support that in set_axes def rename(self, renames=None, to=None, inplace=False, **kwargs): - """Renames axes of the array. + r"""Renames axes of the array. Parameters ---------- @@ -1400,23 +1401,23 @@ def rename(self, renames=None, to=None, inplace=False, **kwargs): >>> sex = Axis('sex=M,F') >>> arr = ndtest([nat, sex]) >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FO 2 3 >>> arr.rename(nat, 'nat2') - nat2\\sex M F + nat2\sex M F BE 0 1 FO 2 3 >>> arr.rename(nat='nat2', sex='sex2') - nat2\\sex2 M F + nat2\sex2 M F BE 0 1 FO 2 3 >>> arr.rename([('nat', 'nat2'), ('sex', 'sex2')]) - nat2\\sex2 M F + nat2\sex2 M F BE 0 1 FO 2 3 >>> arr.rename({'nat': 'nat2', 'sex': 'sex2'}) - nat2\\sex2 M F + nat2\sex2 M F BE 0 1 FO 2 3 """ @@ -1775,7 +1776,7 @@ def align(self, other, join='outer', fill_value=nan, axes=None): @deprecate_kwarg('reverse', 'ascending', {True: False, False: True}) def sort_values(self, key=None, axis=None, ascending=True): - """Sorts values of the array. + r"""Sorts values of the array. Parameters ---------- @@ -1808,7 +1809,7 @@ def sort_values(self, key=None, axis=None, ascending=True): 2 4 10 >>> arr_2D = LArray([[10, 2, 4], [3, 7, 1]], 'a=a0,a1; b=b0..b2') >>> arr_2D - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 10 2 4 a1 3 7 1 >>> # if the array has more than one dimension, sort array with all axes combined @@ -1820,24 +1821,24 @@ def sort_values(self, key=None, axis=None, ascending=True): >>> # sort columns according to the values of the row associated with the label 'a1' >>> arr_2D.sort_values('a1') - a\\b b2 b0 b1 + a\b b2 b0 b1 a0 4 10 2 a1 1 3 7 >>> arr_2D.sort_values('a1', ascending=False) - a\\b b1 b0 b2 + a\b b1 b0 b2 a0 2 10 4 a1 7 3 1 >>> arr_3D = LArray([[[10, 2, 4], [3, 7, 1]], [[5, 1, 6], [2, 8, 9]]], ... 'a=a0,a1; b=b0,b1; c=c0..c2') >>> arr_3D - a b\\c c0 c1 c2 + a b\c c0 c1 c2 a0 b0 10 2 4 a0 b1 3 7 1 a1 b0 5 1 6 a1 b1 2 8 9 >>> # sort columns according to the values of the row associated with the labels 'a0' and 'b1' >>> arr_3D.sort_values(('a0', 'b1')) - a b\\c c2 c0 c1 + a b\c c2 c0 c1 a0 b0 4 10 2 a0 b1 1 3 7 a1 b0 6 5 1 @@ -1846,19 +1847,19 @@ def sort_values(self, key=None, axis=None, ascending=True): Sort along an axis >>> arr_2D - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 10 2 4 a1 3 7 1 >>> # sort values along axis 'a' >>> # equivalent to sorting the values of each column of the array >>> arr_2D.sort_values(axis='a') - a*\\b b0 b1 b2 + a*\b b0 b1 b2 0 3 2 1 1 10 7 4 >>> # sort values along axis 'b' >>> # equivalent to sorting the values of each row of the array >>> arr_2D.sort_values(axis='b') - a\\b* 0 1 2 + a\b* 0 1 2 a0 2 4 10 a1 1 3 7 """ @@ -1898,7 +1899,7 @@ def sort_values(self, key=None, axis=None, ascending=True): @deprecate_kwarg('reverse', 'ascending', {True: False, False: True}) def sort_axes(self, axes=None, ascending=True): - """Sorts axes of the array. + r"""Sorts axes of the array. Parameters ---------- @@ -1916,27 +1917,27 @@ def sort_axes(self, axes=None, ascending=True): -------- >>> a = ndtest("nat=EU,FO,BE; sex=M,F") >>> a - nat\\sex M F + nat\sex M F EU 0 1 FO 2 3 BE 4 5 >>> a.sort_axes('sex') - nat\\sex F M + nat\sex F M EU 1 0 FO 3 2 BE 5 4 >>> a.sort_axes() - nat\\sex F M + nat\sex F M BE 5 4 EU 1 0 FO 3 2 >>> a.sort_axes(('sex', 'nat')) - nat\\sex F M + nat\sex F M BE 5 4 EU 1 0 FO 3 2 >>> a.sort_axes(ascending=False) - nat\\sex M F + nat\sex M F FO 2 3 EU 0 1 BE 4 5 @@ -2130,7 +2131,7 @@ def __setitem__(self, key, value, collapse_slices=True, translate_key=True): # axis, we get combined dimensions out of it. def set(self, value, **kwargs): - """ + r""" Sets a subset of array to value. * all common axes must be either of length 1 or the same length @@ -2145,19 +2146,19 @@ def set(self, value, **kwargs): -------- >>> arr = ndtest((3, 3)) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 a2 6 7 8 >>> arr['a1:', 'b1:'].set(10) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 10 10 a2 6 10 10 >>> arr['a1:', 'b1:'].set(ndtest("a=a1,a2;b=b1,b2")) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 0 1 a2 6 2 3 @@ -2166,7 +2167,7 @@ def set(self, value, **kwargs): # TODO: this should be a private method def reshape(self, target_axes): - """ + r""" Given a list of new axes, changes the shape of the array. The size of the array (= number of elements) must be equal to the product of length of target axes. @@ -2186,7 +2187,7 @@ def reshape(self, target_axes): -------- >>> arr = ndtest((2, 2, 2)) >>> arr - a b\\c c0 c1 + a b\c c0 c1 a0 b0 0 1 a0 b1 2 3 a1 b0 4 5 @@ -2194,7 +2195,7 @@ def reshape(self, target_axes): >>> new_arr = arr.reshape([Axis('a=a0,a1'), ... Axis(['b0c0', 'b0c1', 'b1c0', 'b1c1'], 'bc')]) >>> new_arr - a\\bc b0c0 b0c1 b1c0 b1c1 + a\bc b0c0 b0c1 b1c0 b1c1 a0 0 1 2 3 a1 4 5 6 7 """ @@ -2216,7 +2217,7 @@ def reshape(self, target_axes): # TODO: this should be a private method def reshape_like(self, target): - """ + r""" Same as reshape but with an array as input. Total size (= number of stored data) of the two arrays must be equal. @@ -2228,21 +2229,21 @@ def reshape_like(self, target): -------- >>> arr = zeros((2, 2, 2), dtype=int) >>> arr - {0}* {1}*\\{2}* 0 1 + {0}* {1}*\{2}* 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 >>> new_arr = arr.reshape_like(ndtest((2, 4))) >>> new_arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 0 0 0 a1 0 0 0 0 """ return self.reshape(target.axes) def broadcast_with(self, target): - """ + r""" Returns an array that is (NumPy) broadcastable with target. * all common axes must be either of length 1 or the same length @@ -2293,7 +2294,7 @@ def broadcast_with(self, target): # wonder if there would be a risk of wildcard axes inadvertently leaking. # plus it might be confusing if incompatible labels "work". def ignore_labels(self, axes=None): - """Ignore labels from axes (replace those axes by "wildcard" axes). + r"""Ignore labels from axes (replace those axes by "wildcard" axes). Useful when you want to apply operations between two arrays or subarrays with same shape but incompatible axes @@ -2319,20 +2320,20 @@ def ignore_labels(self, axes=None): >>> b2 = Axis('b=b2,b3') >>> arr1 = ndtest([a, b]) >>> arr1 - a\\b b1 b2 + a\b b1 b2 a1 0 1 a2 2 3 >>> arr1.ignore_labels(b) - a\\b* 0 1 + a\b* 0 1 a1 0 1 a2 2 3 >>> arr1.ignore_labels([a, b]) - a*\\b* 0 1 + a*\b* 0 1 0 0 1 1 2 3 >>> arr2 = ndtest([a, b2]) >>> arr2 - a\\b b2 b3 + a\b b2 b3 a1 0 1 a2 2 3 >>> arr1 * arr2 @@ -2343,15 +2344,15 @@ def ignore_labels(self, axes=None): vs Axis(['b1', 'b2'], 'b') >>> arr1 * arr2.ignore_labels() - a\\b b1 b2 + a\b b1 b2 a1 0 1 a2 4 9 >>> arr1.ignore_labels() * arr2 - a\\b b2 b3 + a\b b2 b3 a1 0 1 a2 4 9 >>> arr1.ignore_labels('a') * arr2.ignore_labels('b') - a\\b b1 b2 + a\b b1 b2 a1 0 1 a2 4 9 """ @@ -2554,7 +2555,7 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam # defaults to 'auto' (ie collapse by default), can be set to False to # force a copy and to True to raise an exception if a view is not possible. def filter(self, collapse=False, **kwargs): - """Filters the array along the axes given as keyword arguments. + r"""Filters the array along the axes given as keyword arguments. The *collapse* argument determines whether consecutive ranges should be collapsed to slices, which is more efficient and returns a view @@ -2567,7 +2568,7 @@ def filter(self, collapse=False, **kwargs): return self.__getitem__(kwargs, collapse) def _axis_aggregate(self, op, axes=(), keepaxes=False, out=None, **kwargs): - """ + r""" Parameters ---------- op : function @@ -2611,7 +2612,7 @@ def _axis_aggregate(self, op, axes=(), keepaxes=False, out=None, **kwargs): return LArray(res_data, res_axes) def _cum_aggregate(self, op, axis): - """ + r""" op is a numpy cumulative aggregate function: func(arr, axis=0). axis is an Axis object, a str or an int. Contrary to other aggregate functions this only supports one axis at a time. @@ -2712,7 +2713,7 @@ def _group_aggregate(self, op, items, keepaxes=False, out=None, **kwargs): return res def _prepare_aggregate(self, op, args, kwargs=None, commutative=False, stack_depth=1): - """converts args to keys & LGroup and kwargs to LGroup""" + r"""converts args to keys & LGroup and kwargs to LGroup""" if kwargs is None: kwargs_items = [] @@ -2918,7 +2919,7 @@ def with_total(self, *args, **kwargs): # for the case where axis is None, we should return an NDGroup # so that arr[arr.labelofmin()] works even if the minimum is on ambiguous labels def labelofmin(self, axis=None): - """Returns labels of the minimum values along a given axis. + r"""Returns labels of the minimum values along a given axis. Parameters ---------- @@ -2940,7 +2941,7 @@ def labelofmin(self, axis=None): >>> sex = Axis('sex=M,F') >>> arr = LArray([[0, 1], [3, 2], [2, 5]], [nat, sex]) >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FR 3 2 IT 2 5 @@ -2961,7 +2962,7 @@ def labelofmin(self, axis=None): argmin = renamed_to(labelofmin, 'argmin') def indexofmin(self, axis=None): - """Returns indices of the minimum values along a given axis. + r"""Returns indices of the minimum values along a given axis. Parameters ---------- @@ -2983,7 +2984,7 @@ def indexofmin(self, axis=None): >>> sex = Axis('sex=M,F') >>> arr = LArray([[0, 1], [3, 2], [2, 5]], [nat, sex]) >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FR 3 2 IT 2 5 @@ -3002,7 +3003,7 @@ def indexofmin(self, axis=None): posargmin = renamed_to(indexofmin, 'posargmin') def labelofmax(self, axis=None): - """Returns labels of the maximum values along a given axis. + r"""Returns labels of the maximum values along a given axis. Parameters ---------- @@ -3024,7 +3025,7 @@ def labelofmax(self, axis=None): >>> sex = Axis('sex=M,F') >>> arr = LArray([[0, 1], [3, 2], [2, 5]], [nat, sex]) >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FR 3 2 IT 2 5 @@ -3045,7 +3046,7 @@ def labelofmax(self, axis=None): argmax = renamed_to(labelofmax, 'argmax') def indexofmax(self, axis=None): - """Returns indices of the maximum values along a given axis. + r"""Returns indices of the maximum values along a given axis. Parameters ---------- @@ -3067,7 +3068,7 @@ def indexofmax(self, axis=None): >>> sex = Axis('sex=M,F') >>> arr = LArray([[0, 1], [3, 2], [2, 5]], [nat, sex]) >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FR 3 2 IT 2 5 @@ -3086,7 +3087,7 @@ def indexofmax(self, axis=None): posargmax = renamed_to(indexofmax, 'posargmax') def labelsofsorted(self, axis=None, ascending=True, kind='quicksort'): - """Returns the labels that would sort this array. + r"""Returns the labels that would sort this array. Performs an indirect sort along the given axis using the algorithm specified by the `kind` keyword. It returns an array of labels of the same shape as `a` that index data along the given axis in sorted order. @@ -3108,17 +3109,17 @@ def labelsofsorted(self, axis=None, ascending=True, kind='quicksort'): -------- >>> arr = LArray([[0, 1], [3, 2], [2, 5]], "nat=BE,FR,IT; sex=M,F") >>> arr - nat\\sex M F + nat\sex M F BE 0 1 FR 3 2 IT 2 5 >>> arr.labelsofsorted('sex') - nat\\sex 0 1 + nat\sex 0 1 BE M F FR F M IT M F >>> arr.labelsofsorted('sex', ascending=False) - nat\\sex 0 1 + nat\sex 0 1 BE F M FR M F IT F M @@ -3134,7 +3135,7 @@ def labelsofsorted(self, axis=None, ascending=True, kind='quicksort'): argsort = renamed_to(labelsofsorted, 'argsort') def indicesofsorted(self, axis=None, ascending=True, kind='quicksort'): - """Returns the indices that would sort this array. + r"""Returns the indices that would sort this array. Performs an indirect sort along the given axis using the algorithm specified by the `kind` keyword. It returns an array of indices with the same axes as `a` that index data along the given axis in sorted order. @@ -3156,17 +3157,17 @@ def indicesofsorted(self, axis=None, ascending=True, kind='quicksort'): -------- >>> arr = LArray([[1, 5], [3, 2], [0, 4]], "nat=BE,FR,IT; sex=M,F") >>> arr - nat\\sex M F + nat\sex M F BE 1 5 FR 3 2 IT 0 4 >>> arr.indicesofsorted('nat') - nat\\sex M F + nat\sex M F 0 2 1 1 0 2 2 1 0 >>> arr.indicesofsorted('nat', ascending=False) - nat\\sex M F + nat\sex M F 0 1 0 1 0 2 2 2 1 @@ -3448,8 +3449,7 @@ def iflat(self): iflat.__doc__ = LArrayFlatIndicesIndexer.__doc__ def copy(self): - """Returns a copy of the array. - """ + r"""Returns a copy of the array. """ return LArray(self.data.copy(), axes=self.axes[:], meta=self.meta) # XXX: we might want to implement this using .groupby().first() @@ -3548,7 +3548,7 @@ def unique(self, axes=None, sort=False, sep='_'): @property def info(self): - """Describes a LArray (metadata + shape and labels for each axis). + r"""Describes a LArray (metadata + shape and labels for each axis). Returns ------- @@ -3580,7 +3580,7 @@ def info(self): return ReprString(str_info) def ratio(self, *axes): - """Returns an array with all values divided by the sum of values along given axes. + r"""Returns an array with all values divided by the sum of values along given axes. Parameters ---------- @@ -3597,21 +3597,21 @@ def ratio(self, *axes): >>> sex = Axis('sex=M,F') >>> a = LArray([[4, 6], [2, 8]], [nat, sex]) >>> a - nat\\sex M F + nat\sex M F BE 4 6 FO 2 8 >>> a.sum() 20 >>> a.ratio() - nat\\sex M F + nat\sex M F BE 0.2 0.3 FO 0.1 0.4 >>> a.ratio('sex') - nat\\sex M F + nat\sex M F BE 0.4 0.6 FO 0.2 0.8 >>> a.ratio('M') - nat\\sex M F + nat\sex M F BE 1.0 1.5 FO 1.0 4.0 """ @@ -3630,7 +3630,7 @@ def ratio(self, *axes): # 1.0 0.6 0.555555555556 # OR (current meaning) # >>> a / a.sum('F') - # age\\sex M F + # age\sex M F # 0 0.0 1.0 # 1 0.666666666667 1.0 # 2 0.8 1.0 @@ -3655,23 +3655,23 @@ def ratio(self, *axes): # [0 1] 2 4 # [1 2] 6 8 # >>> b / b.sum(X.age) - # age\\sex M F + # age\sex M F # [0 1] 0.25 0.333333333333 # [1 2] 0.75 0.666666666667 # >>> b / a.sum(X.age) - # age\\sex M F + # age\sex M F # [0 1] 0.333333333333 0.444444444444 # [1 2] 1.0 0.888888888889 # # >>> a.ratio([0, 1], [2]) # # >>> a.ratio(X.age[[0, 1]], X.age[2]) # >>> a.ratio((X.age[[0, 1]], X.age[2])) - # nat\\sex M F + # nat\sex M F # BE 0.0 1.0 # FO 0.6666666666 1.0 return self / self.sum(*axes) def rationot0(self, *axes): - """Returns a LArray with values array / array.sum(axes) where the sum is not 0, 0 otherwise. + r"""Returns a LArray with values array / array.sum(axes) where the sum is not 0, 0 otherwise. Parameters ---------- @@ -3689,31 +3689,31 @@ def rationot0(self, *axes): >>> arr = LArray([[6, 0, 2], ... [4, 0, 8]], [a, b]) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 6 0 2 a1 4 0 8 >>> arr.sum() 20 >>> arr.rationot0() - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.3 0.0 0.1 a1 0.2 0.0 0.4 >>> arr.rationot0('a') - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.6 0.0 0.2 a1 0.4 0.0 0.8 for reference, the normal ratio method would return: >>> arr.ratio('a') - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.6 nan 0.2 a1 0.4 nan 0.8 """ return self.divnot0(self.sum(*axes)) def percent(self, *axes): - """Returns an array with values given as percent of the total of all values along given axes. + r"""Returns an array with values given as percent of the total of all values along given axes. Parameters ---------- @@ -3730,15 +3730,15 @@ def percent(self, *axes): >>> sex = Axis('sex=M,F') >>> a = LArray([[4, 6], [2, 8]], [nat, sex]) >>> a - nat\\sex M F + nat\sex M F BE 4 6 FO 2 8 >>> a.percent() - nat\\sex M F + nat\sex M F BE 20.0 30.0 FO 10.0 40.0 >>> a.percent('sex') - nat\\sex M F + nat\sex M F BE 40.0 60.0 FO 20.0 80.0 """ @@ -3771,7 +3771,7 @@ def wrapper(self, *args, **kwargs): @_decorate_agg_method(np.all, commutative=True, long_name="AND reduction") def all(self, *args, **kwargs): - """{signature} + r"""{signature} Test whether all selected elements evaluate to True. @@ -3789,14 +3789,14 @@ def all(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> barr = arr < 6 >>> barr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 True True True True a1 True True False False a2 False False False False @@ -3823,7 +3823,7 @@ def all(self, *args, **kwargs): Split an axis in several parts >>> barr.all((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 True True False False a2,a3 False False False False >>> # or equivalently @@ -3832,7 +3832,7 @@ def all(self, *args, **kwargs): Same with renaming >>> barr.all((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 True True False False a23 False False False False >>> # or equivalently @@ -3842,7 +3842,7 @@ def all(self, *args, **kwargs): @_decorate_agg_method(np.all, commutative=True, by_agg=True, long_name="AND reduction") def all_by(self, *args, **kwargs): - """{signature} + r"""{signature} Test whether all selected elements evaluate to True. @@ -3860,14 +3860,14 @@ def all_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> barr = arr < 6 >>> barr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 True True True True a1 True True False False a2 False False False False @@ -3910,7 +3910,7 @@ def all_by(self, *args, **kwargs): @_decorate_agg_method(np.any, commutative=True, long_name="OR reduction") def any(self, *args, **kwargs): - """{signature} + r"""{signature} Test whether any selected elements evaluate to True. @@ -3928,14 +3928,14 @@ def any(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> barr = arr < 6 >>> barr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 True True True True a1 True True False False a2 False False False False @@ -3962,7 +3962,7 @@ def any(self, *args, **kwargs): Split an axis in several parts >>> barr.any((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 True True True True a2,a3 False False False False >>> # or equivalently @@ -3971,7 +3971,7 @@ def any(self, *args, **kwargs): Same with renaming >>> barr.any((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 True True True True a23 False False False False >>> # or equivalently @@ -3981,7 +3981,7 @@ def any(self, *args, **kwargs): @_decorate_agg_method(np.any, commutative=True, by_agg=True, long_name="OR reduction") def any_by(self, *args, **kwargs): - """{signature} + r"""{signature} Test whether any selected elements evaluate to True. @@ -3999,14 +3999,14 @@ def any_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> barr = arr < 6 >>> barr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 True True True True a1 True True False False a2 False False False False @@ -4051,7 +4051,7 @@ def any_by(self, *args, **kwargs): @_decorate_agg_method(np.sum, np.nansum, commutative=True, extra_kwargs=['dtype']) def sum(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the sum of array elements along given axes/groups. @@ -4070,7 +4070,7 @@ def sum(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4097,7 +4097,7 @@ def sum(self, *args, **kwargs): Split an axis in several parts >>> arr.sum((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 4 6 8 10 a2,a3 20 22 24 26 >>> # or equivalently @@ -4106,7 +4106,7 @@ def sum(self, *args, **kwargs): Same with renaming >>> arr.sum((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 4 6 8 10 a23 20 22 24 26 >>> # or equivalently @@ -4116,7 +4116,7 @@ def sum(self, *args, **kwargs): @_decorate_agg_method(np.sum, np.nansum, commutative=True, by_agg=True, extra_kwargs=['dtype'], long_name="sum") def sum_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the sum of array elements for the given axes/groups. @@ -4135,7 +4135,7 @@ def sum_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4179,7 +4179,7 @@ def sum_by(self, *args, **kwargs): # nanprod needs numpy 1.10 @_decorate_agg_method(np.prod, np_nanprod, commutative=True, extra_kwargs=['dtype'], long_name="product") def prod(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the product of array elements along given axes/groups. @@ -4198,7 +4198,7 @@ def prod(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4225,7 +4225,7 @@ def prod(self, *args, **kwargs): Split an axis in several parts >>> arr.prod((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 0 5 12 21 a2,a3 96 117 140 165 >>> # or equivalently @@ -4234,7 +4234,7 @@ def prod(self, *args, **kwargs): Same with renaming >>> arr.prod((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 0 5 12 21 a23 96 117 140 165 >>> # or equivalently @@ -4245,7 +4245,7 @@ def prod(self, *args, **kwargs): @_decorate_agg_method(np.prod, np_nanprod, commutative=True, by_agg=True, extra_kwargs=['dtype'], long_name="product") def prod_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the product of array elements for the given axes/groups. @@ -4264,7 +4264,7 @@ def prod_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4307,7 +4307,7 @@ def prod_by(self, *args, **kwargs): @_decorate_agg_method(np.min, np.nanmin, commutative=True, long_name="minimum", action_verb="search") def min(self, *args, **kwargs): - """{signature} + r"""{signature} Get minimum of array elements along given axes/groups. @@ -4325,7 +4325,7 @@ def min(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4352,7 +4352,7 @@ def min(self, *args, **kwargs): Split an axis in several parts >>> arr.min((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 0 1 2 3 a2,a3 8 9 10 11 >>> # or equivalently @@ -4361,7 +4361,7 @@ def min(self, *args, **kwargs): Same with renaming >>> arr.min((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 0 1 2 3 a23 8 9 10 11 >>> # or equivalently @@ -4371,7 +4371,7 @@ def min(self, *args, **kwargs): @_decorate_agg_method(np.min, np.nanmin, commutative=True, by_agg=True, long_name="minimum", action_verb="search") def min_by(self, *args, **kwargs): - """{signature} + r"""{signature} Get minimum of array elements for the given axes/groups. @@ -4389,7 +4389,7 @@ def min_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4432,7 +4432,7 @@ def min_by(self, *args, **kwargs): @_decorate_agg_method(np.max, np.nanmax, commutative=True, long_name="maximum", action_verb="search") def max(self, *args, **kwargs): - """{signature} + r"""{signature} Get maximum of array elements along given axes/groups. @@ -4450,7 +4450,7 @@ def max(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4477,7 +4477,7 @@ def max(self, *args, **kwargs): Split an axis in several parts >>> arr.max((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 4 5 6 7 a2,a3 12 13 14 15 >>> # or equivalently @@ -4486,7 +4486,7 @@ def max(self, *args, **kwargs): Same with renaming >>> arr.max((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 4 5 6 7 a23 12 13 14 15 >>> # or equivalently @@ -4496,7 +4496,7 @@ def max(self, *args, **kwargs): @_decorate_agg_method(np.max, np.nanmax, commutative=True, by_agg=True, long_name="maximum", action_verb="search") def max_by(self, *args, **kwargs): - """{signature} + r"""{signature} Get maximum of array elements for the given axes/groups. @@ -4514,7 +4514,7 @@ def max_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4557,7 +4557,7 @@ def max_by(self, *args, **kwargs): @_decorate_agg_method(np.mean, np.nanmean, commutative=True, extra_kwargs=['dtype']) def mean(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the arithmetic mean. @@ -4577,7 +4577,7 @@ def mean(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4604,7 +4604,7 @@ def mean(self, *args, **kwargs): Split an axis in several parts >>> arr.mean((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 2.0 3.0 4.0 5.0 a2,a3 10.0 11.0 12.0 13.0 >>> # or equivalently @@ -4613,7 +4613,7 @@ def mean(self, *args, **kwargs): Same with renaming >>> arr.mean((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 2.0 3.0 4.0 5.0 a23 10.0 11.0 12.0 13.0 >>> # or equivalently @@ -4623,7 +4623,7 @@ def mean(self, *args, **kwargs): @_decorate_agg_method(np.mean, np.nanmean, commutative=True, by_agg=True, extra_kwargs=['dtype'], long_name="mean") def mean_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the arithmetic mean. @@ -4643,7 +4643,7 @@ def mean_by(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4686,7 +4686,7 @@ def mean_by(self, *args, **kwargs): @_decorate_agg_method(np.median, np.nanmedian, commutative=True) def median(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the arithmetic median. @@ -4705,12 +4705,12 @@ def median(self, *args, **kwargs): Examples -------- >>> arr = ndtest((4, 4)) - >>> arr[:,:] = [[10, 7, 5, 9], \ - [5, 8, 3, 7], \ - [6, 2, 0, 9], \ - [9, 10, 5, 6]] + >>> arr[:,:] = [[10, 7, 5, 9], + ... [5, 8, 3, 7], + ... [6, 2, 0, 9], + ... [9, 10, 5, 6]] >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 10 7 5 9 a1 5 8 3 7 a2 6 2 0 9 @@ -4737,7 +4737,7 @@ def median(self, *args, **kwargs): Split an axis in several parts >>> arr.median((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 7.5 7.5 4.0 8.0 a2,a3 7.5 6.0 2.5 7.5 >>> # or equivalently @@ -4746,7 +4746,7 @@ def median(self, *args, **kwargs): Same with renaming >>> arr.median((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 7.5 7.5 4.0 8.0 a23 7.5 6.0 2.5 7.5 >>> # or equivalently @@ -4756,7 +4756,7 @@ def median(self, *args, **kwargs): @_decorate_agg_method(np.median, np.nanmedian, commutative=True, by_agg=True, long_name="mediane") def median_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the arithmetic median. @@ -4775,12 +4775,12 @@ def median_by(self, *args, **kwargs): Examples -------- >>> arr = ndtest((4, 4)) - >>> arr[:,:] = [[10, 7, 5, 9], \ - [5, 8, 3, 7], \ - [6, 2, 0, 9], \ - [9, 10, 5, 6]] + >>> arr[:,:] = [[10, 7, 5, 9], + ... [5, 8, 3, 7], + ... [6, 2, 0, 9], + ... [9, 10, 5, 6]] >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 10 7 5 9 a1 5 8 3 7 a2 6 2 0 9 @@ -4827,7 +4827,7 @@ def median_by(self, *args, **kwargs): # percentile needs an explicit method because it has not the same # signature as other aggregate functions (extra argument) def percentile(self, q, *args, **kwargs): - """{signature} + r"""{signature} Computes the qth percentile of the data along the specified axis. @@ -4847,7 +4847,7 @@ def percentile(self, q, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4864,7 +4864,7 @@ def percentile(self, q, *args, **kwargs): 0.75 4.75 8.75 12.75 >>> # several percentile values >>> arr.percentile([25, 50, 75], 'b') - percentile\\a a0 a1 a2 a3 + percentile\a a0 a1 a2 a3 25 0.75 4.75 8.75 12.75 50 1.5 5.5 9.5 13.5 75 2.25 6.25 10.25 14.25 @@ -4880,7 +4880,7 @@ def percentile(self, q, *args, **kwargs): Split an axis in several parts >>> arr.percentile(25, (['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 1.0 2.0 3.0 4.0 a2,a3 9.0 10.0 11.0 12.0 >>> # or equivalently @@ -4889,7 +4889,7 @@ def percentile(self, q, *args, **kwargs): Same with renaming >>> arr.percentile(25, (X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 1.0 2.0 3.0 4.0 a23 9.0 10.0 11.0 12.0 >>> # or equivalently @@ -4915,7 +4915,7 @@ def percentile(self, q, *args, **kwargs): kwargs=['out', 'interpolation', 'skipna', 'keepaxes']) def percentile_by(self, q, *args, **kwargs): - """{signature} + r"""{signature} Computes the qth percentile of the data for the specified axis. @@ -4935,7 +4935,7 @@ def percentile_by(self, q, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -4952,7 +4952,7 @@ def percentile_by(self, q, *args, **kwargs): 3.0 4.0 5.0 6.0 >>> # several percentile values >>> arr.percentile_by([25, 50, 75], 'b') - percentile\\b b0 b1 b2 b3 + percentile\b b0 b1 b2 b3 25 3.0 4.0 5.0 6.0 50 6.0 7.0 8.0 9.0 75 9.0 10.0 11.0 12.0 @@ -5001,7 +5001,7 @@ def percentile_by(self, q, *args, **kwargs): # not commutative def ptp(self, *args, **kwargs): - """{signature} + r"""{signature} Returns the range of values (maximum - minimum). @@ -5017,7 +5017,7 @@ def ptp(self, *args, **kwargs): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 @@ -5044,7 +5044,7 @@ def ptp(self, *args, **kwargs): Split an axis in several parts >>> arr.ptp((['a0', 'a1'], ['a2', 'a3'])) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0,a1 4 4 4 4 a2,a3 4 4 4 4 >>> # or equivalently @@ -5053,7 +5053,7 @@ def ptp(self, *args, **kwargs): Same with renaming >>> arr.ptp((X.a['a0', 'a1'] >> 'a01', X.a['a2', 'a3'] >> 'a23')) - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a01 4 4 4 4 a23 4 4 4 4 >>> # or equivalently @@ -5066,7 +5066,7 @@ def ptp(self, *args, **kwargs): @_decorate_agg_method(np.var, np.nanvar, extra_kwargs=['dtype', 'ddof'], long_name="variance") def var(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the unbiased variance. @@ -5087,10 +5087,10 @@ def var(self, *args, **kwargs): Examples -------- >>> arr = ndtest((2, 8), dtype=float) - >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], \ - [7, 3, 2, 5, 8, 5, 6, 4]] + >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], + ... [7, 3, 2, 5, 8, 5, 6, 4]] >>> arr - a\\b b0 b1 b2 b3 b4 b5 b6 b7 + a\b b0 b1 b2 b3 b4 b5 b6 b7 a0 0.0 3.0 5.0 6.0 4.0 2.0 1.0 3.0 a1 7.0 3.0 2.0 5.0 8.0 5.0 6.0 4.0 >>> arr.var() @@ -5111,7 +5111,7 @@ def var(self, *args, **kwargs): Split an axis in several parts >>> arr.var((['b0', 'b1', 'b3'], 'b5:')) - a\\b b0,b1,b3 b5: + a\b b0,b1,b3 b5: a0 9.0 1.0 a1 4.0 1.0 >>> # or equivalently @@ -5120,7 +5120,7 @@ def var(self, *args, **kwargs): Same with renaming >>> arr.var((X.b['b0', 'b1', 'b3'] >> 'b013', X.b['b5:'] >> 'b567')) - a\\b b013 b567 + a\b b013 b567 a0 9.0 1.0 a1 4.0 1.0 >>> # or equivalently @@ -5130,7 +5130,7 @@ def var(self, *args, **kwargs): @_decorate_agg_method(np.var, np.nanvar, by_agg=True, extra_kwargs=['dtype', 'ddof'], long_name="variance") def var_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the unbiased variance. @@ -5151,10 +5151,10 @@ def var_by(self, *args, **kwargs): Examples -------- >>> arr = ndtest((2, 8), dtype=float) - >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], \ - [7, 3, 2, 5, 8, 5, 6, 4]] + >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], + ... [7, 3, 2, 5, 8, 5, 6, 4]] >>> arr - a\\b b0 b1 b2 b3 b4 b5 b6 b7 + a\b b0 b1 b2 b3 b4 b5 b6 b7 a0 0.0 3.0 5.0 6.0 4.0 2.0 1.0 3.0 a1 7.0 3.0 2.0 5.0 8.0 5.0 6.0 4.0 >>> arr.var_by() @@ -5175,7 +5175,7 @@ def var_by(self, *args, **kwargs): Split an axis in several parts >>> arr.var_by('a', (['b0', 'b1', 'b3'], 'b5:')) - a\\b b0,b1,b3 b5: + a\b b0,b1,b3 b5: a0 9.0 1.0 a1 4.0 1.0 >>> # or equivalently @@ -5184,7 +5184,7 @@ def var_by(self, *args, **kwargs): Same with renaming >>> arr.var_by('a', (X.b['b0', 'b1', 'b3'] >> 'b013', X.b['b5:'] >> 'b567')) - a\\b b013 b567 + a\b b013 b567 a0 9.0 1.0 a1 4.0 1.0 >>> # or equivalently @@ -5194,7 +5194,7 @@ def var_by(self, *args, **kwargs): @_decorate_agg_method(np.std, np.nanstd, extra_kwargs=['dtype', 'ddof'], long_name="standard deviation") def std(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the sample standard deviation. @@ -5218,7 +5218,7 @@ def std(self, *args, **kwargs): >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], ... [7, 3, 2, 5, 8, 5, 6, 4]] >>> arr - a\\b b0 b1 b2 b3 b4 b5 b6 b7 + a\b b0 b1 b2 b3 b4 b5 b6 b7 a0 0.0 3.0 5.0 6.0 4.0 2.0 1.0 3.0 a1 7.0 3.0 2.0 5.0 8.0 5.0 6.0 4.0 >>> arr.std() @@ -5239,7 +5239,7 @@ def std(self, *args, **kwargs): Split an axis in several parts >>> arr.std((['b0', 'b1', 'b3'], 'b5:')) - a\\b b0,b1,b3 b5: + a\b b0,b1,b3 b5: a0 3.0 1.0 a1 2.0 1.0 >>> # or equivalently @@ -5248,7 +5248,7 @@ def std(self, *args, **kwargs): Same with renaming >>> arr.std((X.b['b0', 'b1', 'b3'] >> 'b013', X.b['b5:'] >> 'b567')) - a\\b b013 b567 + a\b b013 b567 a0 3.0 1.0 a1 2.0 1.0 >>> # or equivalently @@ -5259,7 +5259,7 @@ def std(self, *args, **kwargs): @_decorate_agg_method(np.std, np.nanstd, by_agg=True, extra_kwargs=['dtype', 'ddof'], long_name="standard deviation") def std_by(self, *args, **kwargs): - """{signature} + r"""{signature} Computes the sample standard deviation. @@ -5283,7 +5283,7 @@ def std_by(self, *args, **kwargs): >>> arr[:,:] = [[0, 3, 5, 6, 4, 2, 1, 3], ... [7, 3, 2, 5, 8, 5, 6, 4]] >>> arr - a\\b b0 b1 b2 b3 b4 b5 b6 b7 + a\b b0 b1 b2 b3 b4 b5 b6 b7 a0 0.0 3.0 5.0 6.0 4.0 2.0 1.0 3.0 a1 7.0 3.0 2.0 5.0 8.0 5.0 6.0 4.0 >>> arr.std_by() @@ -5304,7 +5304,7 @@ def std_by(self, *args, **kwargs): Split an axis in several parts >>> arr.std_by('a', (['b0', 'b1', 'b3'], 'b5:')) - a\\b b0,b1,b3 b5: + a\b b0,b1,b3 b5: a0 3.0 1.0 a1 2.0 1.0 >>> # or equivalently @@ -5313,7 +5313,7 @@ def std_by(self, *args, **kwargs): Same with renaming >>> arr.std_by('a', (X.b['b0', 'b1', 'b3'] >> 'b013', X.b['b5:'] >> 'b567')) - a\\b b013 b567 + a\b b013 b567 a0 3.0 1.0 a1 2.0 1.0 >>> # or equivalently @@ -5323,7 +5323,7 @@ def std_by(self, *args, **kwargs): # cumulative aggregates def cumsum(self, axis=-1): - """ + r""" Returns the cumulative sum of array elements along an axis. Parameters @@ -5350,19 +5350,19 @@ def cumsum(self, axis=-1): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> arr.cumsum() - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 3 6 a1 4 9 15 22 a2 8 17 27 38 a3 12 25 39 54 >>> arr.cumsum('a') - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 6 8 10 a2 12 15 18 21 @@ -5371,7 +5371,7 @@ def cumsum(self, axis=-1): return self._cum_aggregate(np.cumsum, axis) def cumprod(self, axis=-1): - """ + r""" Returns the cumulative product of array elements. Parameters @@ -5398,19 +5398,19 @@ def cumprod(self, axis=-1): -------- >>> arr = ndtest((4, 4)) >>> arr - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 4 5 6 7 a2 8 9 10 11 a3 12 13 14 15 >>> arr.cumprod() - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 0 0 0 a1 4 20 120 840 a2 8 72 720 7920 a3 12 156 2184 32760 >>> arr.cumprod('a') - a\\b b0 b1 b2 b3 + a\b b0 b1 b2 b3 a0 0 1 2 3 a1 0 5 12 21 a2 0 45 120 231 @@ -5481,7 +5481,7 @@ def opmethod(self, other): __ror__ = _binop('ror') def __matmul__(self, other): - """ + r""" Overrides operator @ for matrix multiplication. Notes @@ -5496,7 +5496,7 @@ def __matmul__(self, other): 0 1 2 >>> arr2d = ndtest((3, 3)) >>> arr2d - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 a2 6 7 8 @@ -5510,17 +5510,17 @@ def __matmul__(self, other): 5 14 23 >>> arr3d = ndtest('c=c0..c2;d=d0..d2;e=e0..e2') >>> arr1d @ arr3d # doctest: +SKIP - c\\e e0 e1 e2 + c\e e0 e1 e2 c0 15 18 21 c1 42 45 48 c2 69 72 75 >>> arr3d @ arr1d # doctest: +SKIP - c\\d d0 d1 d2 + c\d d0 d1 d2 c0 5 14 23 c1 32 41 50 c2 59 68 77 >>> arr3d @ arr3d # doctest: +SKIP - c d\\e e0 e1 e2 + c d\e e0 e1 e2 c0 d0 15 18 21 c0 d1 42 54 66 c0 d2 69 90 111 @@ -5866,7 +5866,7 @@ def isin(self, test_values, assume_unique=False, invert=False): return LArray(np.isin(self.data, test_values, assume_unique=assume_unique, invert=invert), self.axes) def divnot0(self, other): - """Divides array by other, but returns 0.0 where other is 0. + r"""Divides array by other, but returns 0.0 where other is 0. Parameters ---------- @@ -5884,7 +5884,7 @@ def divnot0(self, other): >>> sex = Axis('sex=M,F') >>> a = ndtest((nat, sex)) >>> a - nat\\sex M F + nat\sex M F BE 0 1 FO 2 3 >>> b = ndtest(sex) @@ -5892,11 +5892,11 @@ def divnot0(self, other): sex M F 0 1 >>> a / b - nat\\sex M F + nat\sex M F BE nan 1.0 FO inf 3.0 >>> a.divnot0(b) - nat\\sex M F + nat\sex M F BE 0.0 1.0 FO 0.0 3.0 """ @@ -6109,7 +6109,7 @@ def prepend(self, axis, value, label=None): return self.insert(value, before=IGroup(0, axis=axis), label=label) def extend(self, axis, other): - """Adds an array to self along an axis. + r"""Adds an array to self along an axis. The two arrays must have compatible axes. @@ -6133,24 +6133,24 @@ def extend(self, axis, other): >>> xtype = Axis('type=type1,type2') >>> arr1 = ones([sex, xtype]) >>> arr1 - sex\\type type1 type2 + sex\type type1 type2 M 1.0 1.0 F 1.0 1.0 >>> arr2 = zeros([sex2, xtype]) >>> arr2 - sex\\type type1 type2 + sex\type type1 type2 U 0.0 0.0 >>> arr1.extend('sex', arr2) - sex\\type type1 type2 + sex\type type1 type2 M 1.0 1.0 F 1.0 1.0 U 0.0 0.0 >>> arr3 = zeros([sex2, nat]) >>> arr3 - sex\\nat BE FO + sex\nat BE FO U 0.0 0.0 >>> arr1.extend('sex', arr3) - sex type\\nat BE FO + sex type\nat BE FO M type1 1.0 1.0 M type2 1.0 1.0 F type1 1.0 1.0 @@ -6447,7 +6447,7 @@ def drop(self, labels=None): return LArray(np.delete(self.data, indices, axis_idx), new_axes) def transpose(self, *args): - """Reorder axes. + r"""Reorder axes. By default, reverse axes, otherwise permute the axes according to the list given as argument. @@ -6466,31 +6466,31 @@ def transpose(self, *args): -------- >>> arr = ndtest((2, 2, 2)) >>> arr - a b\\c c0 c1 + a b\c c0 c1 a0 b0 0 1 a0 b1 2 3 a1 b0 4 5 a1 b1 6 7 >>> arr.transpose('b', 'c', 'a') - b c\\a a0 a1 + b c\a a0 a1 b0 c0 0 4 b0 c1 1 5 b1 c0 2 6 b1 c1 3 7 >>> arr.transpose('b') - b a\\c c0 c1 + b a\c c0 c1 b0 a0 0 1 b0 a1 4 5 b1 a0 2 3 b1 a1 6 7 >>> arr.transpose(..., 'a') # doctest: +SKIP - b c\\a a0 a1 + b c\a a0 a1 b0 c0 0 4 b0 c1 1 5 b1 c0 2 6 b1 c1 3 7 >>> arr.transpose('c', ..., 'a') # doctest: +SKIP - c b\\a a0 a1 + c b\a a0 a1 c0 b0 0 4 c0 b1 2 6 c1 b0 1 5 @@ -6577,7 +6577,7 @@ def clip(self, minval=None, maxval=None, out=None): @deprecate_kwarg('transpose', 'wide') def to_csv(self, filepath, sep=',', na_rep='', wide=True, value_name='value', dropna=None, dialect='default', **kwargs): - """ + r""" Writes array to a csv file. Parameters @@ -6607,13 +6607,13 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, value_name='value', dr >>> fname = os.path.join(tmpdir.strpath, 'test.csv') >>> a = ndtest('nat=BE,FO;sex=M,F') >>> a - nat\\sex M F + nat\sex M F BE 0 1 FO 2 3 >>> a.to_csv(fname) >>> with open(fname) as f: ... print(f.read().strip()) - nat\\sex,M,F + nat\sex,M,F BE,0,1 FO,2,3 >>> a.to_csv(fname, sep=';', wide=False) @@ -6648,7 +6648,7 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, value_name='value', dr series.to_csv(filepath, sep=sep, na_rep=na_rep, header=True, **kwargs) def to_hdf(self, filepath, key): - """ + r""" Writes array to a HDF file. A HDF file can contain multiple arrays. @@ -6723,7 +6723,7 @@ def to_stata(self, filepath_or_buffer, **kwargs): @deprecate_kwarg('sheet_name', 'sheet') def to_excel(self, filepath=None, sheet=None, position='A1', overwrite_file=False, clear_sheet=False, header=True, transpose=False, wide=True, value_name='value', engine=None, *args, **kwargs): - """ + r""" Writes array in the specified sheet of specified excel workbook. Parameters @@ -6827,7 +6827,7 @@ def to_excel(self, filepath=None, sheet=None, position='A1', overwrite_file=Fals pd_obj.to_excel(filepath, sheet, *args, engine=engine, **kwargs) def to_clipboard(self, *args, **kwargs): - """Sends the content of the array to clipboard. + r"""Sends the content of the array to clipboard. Using to_clipboard() makes it possible to paste the content of the array into a file (Excel, ascii file,...). @@ -6946,7 +6946,7 @@ def plot(self): Error bars on x axis stacked : boolean, default False in line and bar plots, and True in area plot. If True, create stacked plot. - \**kwargs : keywords + **kwargs : keywords Options to pass to matplotlib plotting method Returns @@ -7001,7 +7001,7 @@ def plot(self): @property def shape(self): - """Returns the shape of the array as a tuple. + r"""Returns the shape of the array as a tuple. Returns ------- @@ -7018,7 +7018,7 @@ def shape(self): @property def ndim(self): - """Returns the number of dimensions of the array. + r"""Returns the number of dimensions of the array. Returns ------- @@ -7035,7 +7035,7 @@ def ndim(self): @property def size(self): - """Returns the number of elements in array. + r"""Returns the number of elements in array. Returns ------- @@ -7052,7 +7052,7 @@ def size(self): @property def nbytes(self): - """Returns the number of bytes used to store the array in memory. + r"""Returns the number of bytes used to store the array in memory. Returns ------- @@ -7069,7 +7069,7 @@ def nbytes(self): @property def memory_used(self): - """Returns the memory consumed by the array in human readable form. + r"""Returns the memory consumed by the array in human readable form. Returns ------- @@ -7086,7 +7086,7 @@ def memory_used(self): @property def dtype(self): - """Returns the type of the data of the array. + r"""Returns the type of the data of the array. Returns ------- @@ -7321,7 +7321,7 @@ def roll(self, axis=None, n=1): # TODO: add support for groups as axis (like aggregates) # eg a.diff(X.year[2018:]) instead of a[2018:].diff(X.year) def diff(self, axis=-1, d=1, n=1, label='upper'): - """Calculates the n-th order discrete difference along a given axis. + r"""Calculates the n-th order discrete difference along a given axis. The first order difference is given by out[n] = a[n + 1] - a[n] along the given axis, higher order differences are calculated by using diff recursively. @@ -7348,22 +7348,22 @@ def diff(self, axis=-1, d=1, n=1, label='upper'): -------- >>> a = ndtest('sex=M,F;type=type1,type2,type3').cumsum('type') >>> a - sex\\type type1 type2 type3 + sex\type type1 type2 type3 M 0 1 3 F 3 7 12 >>> a.diff() - sex\\type type2 type3 + sex\type type2 type3 M 1 2 F 4 5 >>> a.diff(n=2) - sex\\type type3 + sex\type type3 M 1 F 1 >>> a.diff('sex') - sex\\type type1 type2 type3 + sex\type type1 type2 type3 F 3 6 9 >>> a.diff(a.type['type2':]) - sex\\type type3 + sex\type type3 M 2 F 5 """ @@ -7386,7 +7386,7 @@ def diff(self, axis=-1, d=1, n=1, label='upper'): # XXX: this is called pct_change in Pandas (but returns the same results, not results * 100, which I find silly). # Maybe change_rate would be better (because growth is not always positive)? def growth_rate(self, axis=-1, d=1, label='upper'): - """Calculates the growth along a given axis. + r"""Calculates the growth along a given axis. Roughly equivalent to a.diff(axis, d, label) / a[axis.i[:-d]] @@ -7410,26 +7410,26 @@ def growth_rate(self, axis=-1, d=1, label='upper'): >>> data = [[2, 4, 5, 4, 6], [4, 6, 3, 6, 9]] >>> a = LArray(data, "sex=M,F; year=2016..2020") >>> a - sex\\year 2016 2017 2018 2019 2020 + sex\year 2016 2017 2018 2019 2020 M 2 4 5 4 6 F 4 6 3 6 9 >>> a.growth_rate() - sex\\year 2017 2018 2019 2020 + sex\year 2017 2018 2019 2020 M 1.0 0.25 -0.2 0.5 F 0.5 -0.5 1.0 0.5 >>> a.growth_rate(label='lower') - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 1.0 0.25 -0.2 0.5 F 0.5 -0.5 1.0 0.5 >>> a.growth_rate(d=2) - sex\\year 2018 2019 2020 + sex\year 2018 2019 2020 M 1.5 0.0 0.2 F -0.25 0.0 2.0 >>> a.growth_rate('sex') - sex\\year 2016 2017 2018 2019 2020 + sex\year 2016 2017 2018 2019 2020 F 1.0 0.5 -0.4 0.5 0.5 >>> a.growth_rate(a.year[2017:]) - sex\\year 2018 2019 2020 + sex\year 2018 2019 2020 M 0.25 -0.2 0.5 F -0.5 1.0 0.5 """ @@ -7443,7 +7443,7 @@ def growth_rate(self, axis=-1, d=1, label='upper'): return diff / array[axis.i[:-d]].ignore_labels(axis) def compact(self): - """Detects and removes "useless" axes (ie axes for which values are constant over the whole axis) + r"""Detects and removes "useless" axes (ie axes for which values are constant over the whole axis) Returns ------- @@ -7455,7 +7455,7 @@ def compact(self): >>> a = LArray([[1, 2], ... [1, 2]], [Axis('sex=M,F'), Axis('nat=BE,FO')]) >>> a - sex\\nat BE FO + sex\nat BE FO M 1 2 F 1 2 >>> a.compact() @@ -7469,7 +7469,7 @@ def compact(self): return res def combine_axes(self, axes=None, sep='_', wildcard=False): - """Combine several axes into one. + r"""Combine several axes into one. Parameters ---------- @@ -7492,7 +7492,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): -------- >>> arr = ndtest((2, 3)) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> arr.combine_axes() @@ -7503,7 +7503,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): 0 1 2 3 4 5 >>> arr = ndtest((2, 2, 2, 2)) >>> arr - a b c\\d d0 d1 + a b c\d d0 d1 a0 b0 c0 0 1 a0 b0 c1 2 3 a0 b1 c0 4 5 @@ -7513,7 +7513,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): a1 b1 c0 12 13 a1 b1 c1 14 15 >>> arr.combine_axes(('a', 'c')) - a_c b\\d d0 d1 + a_c b\d d0 d1 a0_c0 b0 0 1 a0_c0 b1 4 5 a0_c1 b0 2 3 @@ -7523,7 +7523,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): a1_c1 b0 10 11 a1_c1 b1 14 15 >>> arr.combine_axes({('a', 'c'): 'ac'}) - ac b\\d d0 d1 + ac b\d d0 d1 a0_c0 b0 0 1 a0_c0 b1 4 5 a0_c1 b0 2 3 @@ -7536,13 +7536,13 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): # make several combinations at once >>> arr.combine_axes([('a', 'c'), ('b', 'd')]) - a_c\\b_d b0_d0 b0_d1 b1_d0 b1_d1 + a_c\b_d b0_d0 b0_d1 b1_d0 b1_d1 a0_c0 0 1 4 5 a0_c1 2 3 6 7 a1_c0 8 9 12 13 a1_c1 10 11 14 15 >>> arr.combine_axes({('a', 'c'): 'ac', ('b', 'd'): 'bd'}) - ac\\bd b0_d0 b0_d1 b1_d0 b1_d1 + ac\bd b0_d0 b0_d1 b1_d0 b1_d1 a0_c0 0 1 4 5 a0_c1 2 3 6 7 a1_c0 8 9 12 13 @@ -7575,7 +7575,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False): return transposed.reshape(new_axes) def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fill_value=nan): - """Split axes and returns a new array + r"""Split axes and returns a new array Parameters ---------- @@ -7606,7 +7606,7 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil -------- >>> arr = ndtest((2, 3)) >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> combined = arr.combine_axes() @@ -7614,7 +7614,7 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil a_b a0_b0 a0_b1 a0_b2 a1_b0 a1_b1 a1_b2 0 1 2 3 4 5 >>> combined.split_axes() - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 @@ -7624,8 +7624,8 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil >>> combined a_b a0b0 a0b1 a0b2 a1b0 a1b1 a1b2 0 1 2 3 4 5 - >>> combined.split_axes('a_b', regex='(\\\\w{2})(\\\\w{2})') - a\\b b0 b1 b2 + >>> combined.split_axes('a_b', regex=r'(\w{2})(\w{2})') + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 @@ -7633,14 +7633,14 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil >>> combined = ndtest('a_b=a0_b0..a1_b1; c_d=c0_d0..c1_d1') >>> combined - a_b\\c_d c0_d0 c0_d1 c1_d0 c1_d1 + a_b\c_d c0_d0 c0_d1 c1_d0 c1_d1 a0_b0 0 1 2 3 a0_b1 4 5 6 7 a1_b0 8 9 10 11 a1_b1 12 13 14 15 >>> # equivalent to combined.split_axes() which split all axes whose name contains the `sep` delimiter. >>> combined.split_axes(['a_b', 'c_d']) - a b c\\d d0 d1 + a b c\d d0 d1 a0 b0 c0 0 1 a0 b0 c1 2 3 a0 b1 c0 4 5 @@ -7650,7 +7650,7 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil a1 b1 c0 12 13 a1 b1 c1 14 15 >>> combined.split_axes({'a_b': ('A', 'B'), 'c_d': ('C', 'D')}) - A B C\\D d0 d1 + A B C\D d0 d1 a0 b0 c0 0 1 a0 b0 c1 2 3 a0 b1 c0 4 5 @@ -8107,7 +8107,7 @@ def zeros(axes, title=None, dtype=float, order='C', meta=None): def zeros_like(array, title=None, dtype=None, order='K', meta=None): - """Returns an array with the same axes as array and filled with zeros. + r"""Returns an array with the same axes as array and filled with zeros. Parameters ---------- @@ -8133,7 +8133,7 @@ def zeros_like(array, title=None, dtype=None, order='K', meta=None): -------- >>> a = ndtest((2, 3)) >>> zeros_like(a) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 0 0 a1 0 0 0 """ @@ -8143,7 +8143,7 @@ def zeros_like(array, title=None, dtype=None, order='K', meta=None): @_check_axes_argument def ones(axes, title=None, dtype=float, order='C', meta=None): - """Returns an array with the specified axes and filled with ones. + r"""Returns an array with the specified axes and filled with ones. Parameters ---------- @@ -8169,7 +8169,7 @@ def ones(axes, title=None, dtype=float, order='C', meta=None): >>> nat = Axis('nat=BE,FO') >>> sex = Axis('sex=M,F') >>> ones([nat, sex]) - nat\\sex M F + nat\sex M F BE 1.0 1.0 FO 1.0 1.0 """ @@ -8179,7 +8179,7 @@ def ones(axes, title=None, dtype=float, order='C', meta=None): def ones_like(array, title=None, dtype=None, order='K', meta=None): - """Returns an array with the same axes as array and filled with ones. + r"""Returns an array with the same axes as array and filled with ones. Parameters ---------- @@ -8205,7 +8205,7 @@ def ones_like(array, title=None, dtype=None, order='K', meta=None): -------- >>> a = ndtest((2, 3)) >>> ones_like(a) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 1 1 1 a1 1 1 1 """ @@ -8216,7 +8216,7 @@ def ones_like(array, title=None, dtype=None, order='K', meta=None): @_check_axes_argument def empty(axes, title=None, dtype=float, order='C', meta=None): - """Returns an array with the specified axes and uninitialized (arbitrary) data. + r"""Returns an array with the specified axes and uninitialized (arbitrary) data. Parameters ---------- @@ -8242,7 +8242,7 @@ def empty(axes, title=None, dtype=float, order='C', meta=None): >>> nat = Axis('nat=BE,FO') >>> sex = Axis('sex=M,F') >>> empty([nat, sex]) # doctest: +SKIP - nat\\sex M F + nat\sex M F BE 2.47311483356e-315 2.47498446195e-315 FO 0.0 6.07684618082e-31 """ @@ -8252,7 +8252,7 @@ def empty(axes, title=None, dtype=float, order='C', meta=None): def empty_like(array, title=None, dtype=None, order='K', meta=None): - """Returns an array with the same axes as array and uninitialized (arbitrary) data. + r"""Returns an array with the same axes as array and uninitialized (arbitrary) data. Parameters ---------- @@ -8278,7 +8278,7 @@ def empty_like(array, title=None, dtype=None, order='K', meta=None): -------- >>> a = ndtest((3, 2)) >>> empty_like(a) # doctest: +SKIP - a\\b b0 b1 + a\b b0 b1 a0 2.12199579097e-314 6.36598737388e-314 a1 1.06099789568e-313 1.48539705397e-313 a2 1.90979621226e-313 2.33419537056e-313 @@ -8290,7 +8290,7 @@ def empty_like(array, title=None, dtype=None, order='K', meta=None): # We cannot use @_check_axes_argument here because an integer fill_value would be considered as an error def full(axes, fill_value, title=None, dtype=None, order='C', meta=None): - """Returns an array with the specified axes and filled with fill_value. + r"""Returns an array with the specified axes and filled with fill_value. Parameters ---------- @@ -8318,7 +8318,7 @@ def full(axes, fill_value, title=None, dtype=None, order='C', meta=None): >>> nat = Axis('nat=BE,FO') >>> sex = Axis('sex=M,F') >>> full([nat, sex], 42.0) - nat\\sex M F + nat\sex M F BE 42.0 42.0 FO 42.0 42.0 >>> initial_value = ndtest([sex]) @@ -8326,7 +8326,7 @@ def full(axes, fill_value, title=None, dtype=None, order='C', meta=None): sex M F 0 1 >>> full([nat, sex], initial_value) - nat\\sex M F + nat\sex M F BE 0 1 FO 0 1 """ @@ -8342,7 +8342,7 @@ def full(axes, fill_value, title=None, dtype=None, order='C', meta=None): def full_like(array, fill_value, title=None, dtype=None, order='K', meta=None): - """Returns an array with the same axes and type as input array and filled with fill_value. + r"""Returns an array with the same axes and type as input array and filled with fill_value. Parameters ---------- @@ -8370,7 +8370,7 @@ def full_like(array, fill_value, title=None, dtype=None, order='K', meta=None): -------- >>> a = ndtest((2, 3)) >>> full_like(a, 5) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 5 5 5 a1 5 5 5 """ @@ -8384,7 +8384,7 @@ def full_like(array, fill_value, title=None, dtype=None, order='K', meta=None): # XXX: would it be possible to generalize to multiple axes? def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None, meta=None): - """ + r""" Creates an array by sequentially applying modifications to the array along axis. The value for each label in axis will be given by sequentially transforming the value for the previous label. @@ -8434,7 +8434,7 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None sex M F 1 2 >>> sequence(year, 1.0, inc) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 1.0 2.0 3.0 4.0 F 1.0 3.0 5.0 7.0 >>> mult = LArray([2, 3], [sex]) @@ -8442,7 +8442,7 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None sex M F 2 3 >>> sequence(year, 1.0, mult=mult) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 1.0 2.0 4.0 8.0 F 1.0 3.0 9.0 27.0 >>> initial = LArray([3, 4], [sex]) @@ -8450,15 +8450,15 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None sex M F 3 4 >>> sequence(year, initial, 1) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 3 4 5 6 F 4 5 6 7 >>> sequence(year, initial, mult=2) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 3 6 12 24 F 4 8 16 32 >>> sequence(year, initial, inc, mult) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 3 7 15 31 F 4 14 44 134 >>> def modify(prev_value): @@ -8470,7 +8470,7 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None {0}* 0 1 2 0 1 2 >>> sequence('year', axes=(sex, year)) - sex\\year 2016 2017 2018 2019 + sex\year 2016 2017 2018 2019 M 0 1 2 3 F 0 1 2 3 @@ -8620,7 +8620,7 @@ def ndrange(axes, start=0, title=None, dtype=int): @_check_axes_argument def ndtest(shape_or_axes, start=0, label_start=0, title=None, dtype=int, meta=None): - """Returns test array with given shape. + r"""Returns test array with given shape. Axes are named by single letters starting from 'a'. Axes labels are constructed using a '{axis_name}{label_pos}' pattern (e.g. 'a0'). @@ -8656,32 +8656,32 @@ def ndtest(shape_or_axes, start=0, label_start=0, title=None, dtype=int, meta=No a a0 a1 a2 a3 a4 a5 0 1 2 3 4 5 >>> ndtest((2, 3)) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> ndtest((2, 3), label_start=1) - a\\b b1 b2 b3 + a\b b1 b2 b3 a1 0 1 2 a2 3 4 5 >>> ndtest((2, 3), start=2) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 2 3 4 a1 5 6 7 >>> ndtest((2, 3), dtype=float) - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0.0 1.0 2.0 a1 3.0 4.0 5.0 Create test array by passing axes >>> ndtest("nat=BE,FO;sex=M,F") - nat\\sex M F + nat\sex M F BE 0 1 FO 2 3 >>> nat = Axis("nat=BE,FO") >>> sex = Axis("sex=M,F") >>> ndtest([nat, sex]) - nat\\sex M F + nat\sex M F BE 0 1 FO 2 3 """ @@ -8720,7 +8720,7 @@ def kth_diag_indices(shape, k): def diag(a, k=0, axes=(0, 1), ndim=2, split=True): - """ + r""" Extracts a diagonal or construct a diagonal array. Parameters @@ -8749,7 +8749,7 @@ def diag(a, k=0, axes=(0, 1), ndim=2, split=True): >>> sex = Axis('sex=M,F') >>> a = ndtest([nat, sex], start=1) >>> a - nat\\sex M F + nat\sex M F BE 1 2 FO 3 4 >>> d = diag(a) @@ -8757,7 +8757,7 @@ def diag(a, k=0, axes=(0, 1), ndim=2, split=True): nat_sex BE_M FO_F 1 4 >>> diag(d) - nat\\sex M F + nat\sex M F BE 1 0 FO 0 4 >>> a = ndtest(sex, start=1) @@ -8765,7 +8765,7 @@ def diag(a, k=0, axes=(0, 1), ndim=2, split=True): sex M F 1 2 >>> diag(a) - sex\\sex M F + sex\sex M F M 1 0 F 0 2 """ @@ -8802,7 +8802,7 @@ def diag(a, k=0, axes=(0, 1), ndim=2, split=True): @_check_axes_argument def labels_array(axes, title=None, meta=None): - """Returns an array with specified axes and the combination of + r"""Returns an array with specified axes and the combination of corresponding labels as values. Parameters @@ -8826,14 +8826,14 @@ def labels_array(axes, title=None, meta=None): sex M F M F >>> labels_array((nat, sex)) - nat sex\\axis nat sex + nat sex\axis nat sex BE M BE M BE F BE F FO M FO M FO F FO F """ # >>> labels_array((nat, sex)) - # nat\\sex M F + # nat\sex M F # BE BE,M BE,F # FO FO,M FO,F meta = _handle_meta(meta, title) @@ -8859,7 +8859,7 @@ def identity(axis): def eye(rows, columns=None, k=0, title=None, dtype=None, meta=None): - """Returns a 2-D array with ones on the diagonal and zeros elsewhere. + r"""Returns a 2-D array with ones on the diagonal and zeros elsewhere. Parameters ---------- @@ -8886,22 +8886,22 @@ def eye(rows, columns=None, k=0, title=None, dtype=None, meta=None): Examples -------- >>> eye(2, dtype=int) - {0}*\\{1}* 0 1 + {0}*\{1}* 0 1 0 1 0 1 0 1 >>> sex = Axis('sex=M,F') >>> eye(sex) - sex\\sex M F + sex\sex M F M 1.0 0.0 F 0.0 1.0 >>> age = Axis('age=0..2') >>> eye(age, sex) - age\\sex M F + age\sex M F 0 1.0 0.0 1 0.0 1.0 2 0.0 0.0 >>> eye(3, k=1) - {0}*\\{1}* 0 1 2 + {0}*\{1}* 0 1 2 0 0.0 1.0 0.0 1 0.0 0.0 1.0 2 0.0 0.0 0.0 @@ -9319,7 +9319,7 @@ def _equal_modulo_len1(shape1, shape2): # a[ones(a.axes[axes], dtype=bool)] # but if we had assigned axes names from the start (without dropping them) this wouldn't be a problem. def make_numpy_broadcastable(values, min_axes=None): - """ + r""" Returns values where LArrays are (NumPy) broadcastable between them. For that to be possible, all common axes must be compatible (see Axis class documentation). Extra axes (in any array) can have any length. @@ -9359,7 +9359,7 @@ def make_numpy_broadcastable(values, min_axes=None): def raw_broadcastable(values, min_axes=None): - """ + r""" same as make_numpy_broadcastable but returns numpy arrays """ arrays, res_axes = make_numpy_broadcastable(values, min_axes=min_axes) diff --git a/larray/core/axis.py b/larray/core/axis.py index 2d8f81baa..a0f8dd173 100644 --- a/larray/core/axis.py +++ b/larray/core/axis.py @@ -23,7 +23,7 @@ class Axis(ABCAxis): - """ + r""" Represents an axis. It consists of a name and a list of labels. Parameters @@ -156,7 +156,7 @@ def _sorted_values(self): @lazy_attribute def i(self): - """ + r""" Allows to define a subset using positions along the axis instead of labels. @@ -179,7 +179,7 @@ def i(self): @property def labels(self): - """ + r""" labels of the axis. """ return self._labels @@ -202,7 +202,7 @@ def labels(self, labels): self._iswildcard = iswildcard def by(self, length, step=None, template=None): - """Split axis into several groups of specified length. + r"""Split axis into several groups of specified length. Parameters ---------- @@ -238,7 +238,7 @@ def by(self, length, step=None, template=None): return self[:].by(length, step, template) def extend(self, labels): - """ + r""" Append new labels to an axis or increase its length in case of wildcard axis. Note that `extend` does not occur in-place: a new axis object is allocated, filled and returned. @@ -277,7 +277,7 @@ def extend(self, labels): return Axis(labels, self.name) def split(self, sep='_', names=None, regex=None, return_labels=False): - """Split axis and returns a list of Axis. + r"""Split axis and returns a list of Axis. Parameters ---------- @@ -339,7 +339,7 @@ def split(self, sep='_', names=None, regex=None, return_labels=False): return split_axes def insert(self, new_labels, before=None, after=None): - """ + r""" Return a new axis with `new_labels` inserted before `before` or after `after`. Parameters @@ -409,7 +409,7 @@ def iswildcard(self): return self._iswildcard def _group(self, *args, **kwargs): - """ + r""" Deprecated. Parameters @@ -441,7 +441,7 @@ def group(self, *args, **kwargs): raise NotImplementedError('Axis.group is deprecated. Use {} instead.'.format(syntax)) def all(self, name=None): - """ + r""" (Deprecated) Returns a group containing all labels. Parameters @@ -456,7 +456,7 @@ def all(self, name=None): # TODO: make this method private and drop name argument (it is never used) def subaxis(self, key, name=None): - """ + r""" Returns an axis for a sub-array. Parameters @@ -491,7 +491,7 @@ def subaxis(self, key, name=None): return Axis(labels, name) def iscompatible(self, other): - """ + r""" Checks if self is compatible with another axis. * Two non-wildcard axes are compatible if they have the same name and labels. @@ -538,7 +538,7 @@ def iscompatible(self, other): return np.array_equal(self.labels, other.labels) def equals(self, other): - """ + r""" Checks if self is equal to another axis. Two axes are equal if they have the same name and label(s). @@ -573,7 +573,7 @@ def equals(self, other): (len(self) == len(other) if self.iswildcard else np.array_equal(self.labels, other.labels)) def matching(self, deprecated=None, pattern=None, regex=None): - """ + r""" Returns a group with all the labels matching the specified pattern or regular expression. Parameters @@ -647,7 +647,7 @@ def matching(self, deprecated=None, pattern=None, regex=None): matches = renamed_to(matching, 'matches') def startingwith(self, prefix): - """ + r""" Returns a group with the labels starting with the specified string. Parameters @@ -673,7 +673,7 @@ def startingwith(self, prefix): startswith = renamed_to(startingwith, 'startswith') def endingwith(self, suffix): - """ + r""" Returns a group with the labels ending with the specified string. Parameters @@ -699,7 +699,7 @@ def endingwith(self, suffix): endswith = renamed_to(endingwith, 'endswith') def containing(self, substring): - """ + r""" Returns a group with all the labels containing the specified substring. Parameters @@ -729,7 +729,7 @@ def __iter__(self): return iter([IGroup(i, None, self) for i in range(self._length)]) def __getitem__(self, key): - """ + r""" Returns a group (list or unique element) of label(s) usable in .sum or .filter key is a label-based key (other axis, slice and fancy indexing are supported) @@ -811,7 +811,7 @@ def _is_key_type_compatible(self, key): return key_kind == label_kind or key_kind == 'O' or label_kind == 'O' or py2_str_match def index(self, key): - """ + r""" Translates a label key to its numerical index counterpart. Parameters @@ -949,7 +949,7 @@ def __repr__(self): return 'Axis(%r, %r)' % (labels, self.name) def labels_summary(self): - """ + r""" Returns a short representation of the labels. Examples @@ -963,7 +963,7 @@ def repr_on_strings(v): # method factory def _binop(opname): - """ + r""" Method factory to create binary operators special methods. """ fullname = '__%s__' % opname @@ -1020,14 +1020,14 @@ def opmethod(self, other): __matmul__ = _binop('matmul') def __larray__(self): - """ + r""" Returns axis as LArray. """ from .array import labels_array return labels_array(self) def copy(self): - """ + r""" Returns a copy of the axis. """ new_axis = Axis([], self.name) @@ -1041,7 +1041,7 @@ def copy(self): return new_axis def replace(self, old, new=None): - """ + r""" Returns a new axis with some labels replaced. Parameters @@ -1087,7 +1087,7 @@ def replace(self, old, new=None): return Axis(labels, self.name) def apply(self, func): - """ + r""" Returns a new axis with the labels transformed by func. Parameters @@ -1110,7 +1110,7 @@ def apply(self, func): # XXX: rename to named like Group? def rename(self, name): - """ + r""" Renames the axis. Parameters @@ -1141,7 +1141,7 @@ def _rename(self, name): raise TypeError("Axis._rename is deprecated, use Axis.rename instead") def union(self, other): - """Returns axis with the union of this axis labels and other labels. + r"""Returns axis with the union of this axis labels and other labels. Labels relative order will be kept intact, but only unique labels will be returned. Labels from this axis will be before labels from other. @@ -1177,7 +1177,7 @@ def union(self, other): return Axis(unique_multi((self.labels, other)), self.name) def intersection(self, other): - """Returns axis with the (set) intersection of this axis labels and other labels. + r"""Returns axis with the (set) intersection of this axis labels and other labels. In other words, this will use labels from this axis if they are also in other. Labels relative order will be kept intact. @@ -1214,7 +1214,7 @@ def intersection(self, other): return Axis([l for l in self.labels if l in to_keep], self.name) def difference(self, other): - """Returns axis with the (set) difference of this axis labels and other labels. + r"""Returns axis with the (set) difference of this axis labels and other labels. In other words, this will use labels from this axis if they are not in other. Labels relative order will be kept intact. @@ -1251,7 +1251,7 @@ def difference(self, other): return Axis([l for l in self.labels if l not in to_drop], self.name) def align(self, other, join='outer'): - """Align axis with other object using specified join method. + r"""Align axis with other object using specified join method. Parameters ---------- @@ -1305,7 +1305,7 @@ def align(self, other, join='outer'): return self def to_hdf(self, filepath, key=None): - """ + r""" Writes axis to a HDF file. A HDF file can contain multiple axes. @@ -1360,7 +1360,7 @@ def dtype(self): return self._labels.dtype def ignore_labels(self): - """Returns a wildcard axis with the same name and length than this axis. + r"""Returns a wildcard axis with the same name and length than this axis. Useful when you want to apply operations between two arrays with the same shape but incompatible axes (different labels). @@ -1399,7 +1399,7 @@ def _make_axis(obj): # functionality than just a named tuple class AxisCollection(object): __slots__ = ('_list', '_map') - """ + r""" Represents a collection of axes. Parameters @@ -1610,7 +1610,7 @@ def _ipython_key_completions_(self): # XXX: I wonder if this whole positional crap should really be part of AxisCollection or the default behavior. # It could either be moved to make_numpy_broadcastable or made non default def get_by_pos(self, key, i): - """ + r""" Returns axis corresponding to a key, or to position i if the key has no name and key object not found. Parameters @@ -1714,7 +1714,7 @@ def __radd__(self, other): return result def __and__(self, other): - """ + r""" Returns the intersection of this collection and other. """ if not isinstance(other, AxisCollection): @@ -1728,7 +1728,7 @@ def contains(col, i, axis): return AxisCollection([axis for i, axis in enumerate(self) if contains(other, i, axis)]) def __eq__(self, other): - """ + r""" Other collection compares equal if all axes compare equal and in the same order. Works with a list. """ if self is other: @@ -1758,7 +1758,7 @@ def __contains__(self, key): return key in self._map def isaxis(self, value): - """ + r""" Tests if input is an Axis object or the name of an axis contained in self. Parameters @@ -1815,7 +1815,7 @@ def __repr__(self): # TODO: kill name argument (does not seem to be used anywhere def get(self, key, default=None, name=None): - """ + r""" Returns axis corresponding to key. If not found, the argument `name` is used to create a new Axis. If `name` is None, the `default` axis is then returned. @@ -1851,7 +1851,7 @@ def get(self, key, default=None, name=None): return Axis(1, name) def get_all(self, key): - """ + r""" Returns all axes from key if present and length 1 wildcard axes otherwise. Parameters @@ -1897,7 +1897,7 @@ def get_pos_default(k, i): return AxisCollection([get_pos_default(k, i) for i, k in enumerate(key)]) def keys(self): - """ + r""" Returns list of all axis names. Examples @@ -1912,7 +1912,7 @@ def keys(self): return [a.name for a in self._list] def pop(self, axis=-1): - """ + r""" Removes and returns an axis. Parameters @@ -1946,7 +1946,7 @@ def pop(self, axis=-1): return axis def append(self, axis): - """ + r""" Appends axis at the end of the collection. Parameters @@ -1971,7 +1971,7 @@ def append(self, axis): self[len(self):len(self)] = [axis] def check_compatible(self, axes): - """ + r""" Checks if axes passed as argument are compatible with those contained in the collection. Raises ValueError if not. @@ -1992,7 +1992,7 @@ def check_compatible(self, axes): # TODO: deprecate validate argument (unused) # TODO: deprecate replace_wildcards argument (unused) def extend(self, axes, validate=True, replace_wildcards=False): - """ + r""" Extends the collection by appending the axes from `axes`. Parameters @@ -2051,7 +2051,7 @@ def get_axis(col, i, axis): self[old_axis] = axis def index(self, axis, compatible=False): - """ + r""" Returns the index of axis. `axis` can be a name or an Axis object (or an index). If the Axis object itself exists in the list, index() @@ -2128,7 +2128,7 @@ def index(self, axis, compatible=False): # XXX: we might want to return a new AxisCollection (same question for other inplace operations: # append, extend, pop, __delitem__, __setitem__) def insert(self, index, axis): - """ + r""" Inserts axis before index. Parameters @@ -2155,7 +2155,7 @@ def insert(self, index, axis): self[index:index] = [axis] def copy(self): - """ + r""" Returns a copy. """ return self[:] @@ -2225,7 +2225,7 @@ def rename(self, renames=None, to=None, **kwargs): # it is used in LArray.set_axes but if it is only there, shouldn't the support for that be # moved there? def replace(self, axes_to_replace=None, new_axis=None, inplace=False, **kwargs): - """Replace one, several or all axes of the collection. + r"""Replace one, several or all axes of the collection. Parameters ---------- @@ -2483,7 +2483,7 @@ def set_labels(self, axis=None, labels=None, inplace=False, **kwargs): # TODO: deprecate method (should use __sub__ instead) def without(self, axes): - """ + r""" Returns a new collection without some axes. You can use a comma separated list of names. @@ -2526,7 +2526,7 @@ def without(self, axes): return self - axes def __sub__(self, axes): - """ + r""" See Also -------- without @@ -2784,7 +2784,7 @@ def _translated_key(self, key): for axis in self) def _key_to_raw_and_axes(self, key, collapse_slices=False, translate_key=True): - """ + r""" Transforms any key (from LArray.__getitem__) to a raw numpy key, the resulting axes, and potentially a tuple of indices to transpose axes back to where they were. @@ -2910,7 +2910,7 @@ def slice_to_sequence(axis, axis_key): @property def labels(self): - """ + r""" Returns the list of labels of the axes. Returns @@ -2930,7 +2930,7 @@ def labels(self): @property def names(self): - """ + r""" Returns the list of (raw) names of the axes. Returns @@ -2976,7 +2976,7 @@ def display_name(i, axis): @property def ids(self): - """ + r""" Returns the list of ids of the axes. Returns @@ -3000,7 +3000,7 @@ def ids(self): for i, axis in enumerate(self._list)] def axis_id(self, axis): - """ + r""" Returns the id of an axis. Returns @@ -3026,7 +3026,7 @@ def axis_id(self, axis): @property def shape(self): - """ + r""" Returns the shape of the collection. Returns @@ -3046,7 +3046,7 @@ def shape(self): @property def size(self): - """ + r""" Returns the size of the collection, i.e. the number of elements of the array. @@ -3067,7 +3067,7 @@ def size(self): @property def info(self): - """ + r""" Describes the collection (shape and labels for each axis). Returns @@ -3094,7 +3094,7 @@ def info(self): # XXX: instead of front_if_spread, we might want to require axes to be contiguous # (ie the caller would have to transpose axes before calling this) def combine_axes(self, axes=None, sep='_', wildcard=False, front_if_spread=False): - """Combine several axes into one. + r"""Combine several axes into one. Parameters ---------- @@ -3211,7 +3211,7 @@ def combine_axes(self, axes=None, sep='_', wildcard=False, front_if_spread=False return new_axes def split_axes(self, axes=None, sep='_', names=None, regex=None): - """Split axes and returns a new collection + r"""Split axes and returns a new collection The split axes are inserted where the combined axis was. @@ -3264,7 +3264,7 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None): AxisCollection([ Axis(['a0b0', 'a0b1', 'a0b2', 'a1b0', 'a1b1', 'a1b2'], 'a_b') ]) - >>> combined.split_axes('a_b', regex='(\\\\w{2})(\\\\w{2})') + >>> combined.split_axes('a_b', regex=r'(\w{2})(\w{2})') AxisCollection([ Axis(['a0', 'a1'], 'a'), Axis(['b0', 'b1', 'b2'], 'b') @@ -3317,7 +3317,7 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None): split_axis = renamed_to(split_axes, 'split_axis') def align(self, other, join='outer', axes=None): - """Align this axis collection with another. + r"""Align this axis collection with another. This ensures all common axes are compatible. @@ -3460,7 +3460,7 @@ def _flat_lookup(self, flat_indices): axes='axis') def _adv_keys_to_combined_axis_la_keys(self, key, wildcard=False, sep='_'): - """ + r""" Returns key with the non-LArray "advanced indexing" key parts transformed to LArrays with a combined axis. Scalar, slice and LArray key parts are just left as is. @@ -3551,7 +3551,7 @@ def __repr__(self): return 'AxisReference(%r)' % self.name def evaluate(self, context): - """ + r""" Parameters ---------- context : AxisCollection diff --git a/larray/core/group.py b/larray/core/group.py index 52030d474..95a3db458 100644 --- a/larray/core/group.py +++ b/larray/core/group.py @@ -17,7 +17,7 @@ def _slice_to_str(key, repr_func=str): - """ + r""" Converts a slice to a string Examples @@ -40,7 +40,7 @@ def _slice_to_str(key, repr_func=str): def irange(start, stop, step=None): - """Create a range, with inclusive stop bound and automatic sign for step. + r"""Create a range, with inclusive stop bound and automatic sign for step. Parameters ---------- @@ -81,7 +81,7 @@ def irange(start, stop, step=None): def generalized_range(start, stop, step=1): - """Create a range, with inclusive stop bound and automatic sign for step. Bounds can be strings. + r"""Create a range, with inclusive stop bound and automatic sign for step. Bounds can be strings. Parameters ---------- @@ -199,7 +199,7 @@ def generalized_range(start, stop, step=1): def _range_str_to_range(s, stack_depth=1): - """ + r""" Converts a range string to a range (of values). The end point is included. @@ -247,7 +247,7 @@ def _range_str_to_range(s, stack_depth=1): def _range_to_slice(seq, length=None): - """ + r""" Returns a slice if possible (including for sequences of 1 element) otherwise returns the input sequence itself Parameters @@ -331,7 +331,7 @@ def _seq_group_to_name(seq): def _to_tick(v): - """ + r""" Converts any value to a tick (ie makes it hashable, and acceptable as an ndarray element) scalar -> not modified @@ -374,7 +374,7 @@ def _to_tick(v): # TODO: remove the conversion to list in doctests once Python 2 is dropped def _to_ticks(s, parse_single_int=False): - """ + r""" Makes a (list of) value(s) usable as the collection of labels for an Axis (ie hashable). Strip strings, split them on ',' and translate "range strings" to list of values **including the end point** ! @@ -438,7 +438,7 @@ def _to_ticks(s, parse_single_int=False): def _seq_str_to_seq(s, stack_depth=1, parse_single_int=False): - """ + r""" Converts a sequence string to its sequence (or scalar) Parameters @@ -481,7 +481,7 @@ def to_seq(b, stack_depth=1): def _to_key(v, stack_depth=1, parse_single_int=False): - """ + r""" Converts a value to a key usable for indexing (slice object, list of values,...). Strings are split on ',' and stripped. Colons (:) are interpreted as slices. @@ -584,7 +584,7 @@ def _to_key(v, stack_depth=1, parse_single_int=False): def _to_keys(value, stack_depth=1): - """ + r""" Converts a (collection of) group(s) to a structure usable for indexing. 'label' or ['l1', 'l2'] or [['l1', 'l2'], ['l3']] @@ -670,7 +670,7 @@ def _translate_group_key_hdf(key): # TODO: kill this function def union(*args): # TODO: add support for LGroup and lists - """ + r""" Returns the union of several "value strings" as a list. Parameters @@ -694,7 +694,7 @@ def union(*args): class IGroupMaker(object): - """ + r""" Generates a new instance of IGroup for a given axis and key. Attributes @@ -786,7 +786,7 @@ def __str__(self): # TODO: rename to "to_positional" def translate(self, bound=None, stop=False): - """ + r""" Translate key to a position if it is not already Parameters @@ -801,7 +801,7 @@ def translate(self, bound=None, stop=False): raise NotImplementedError() def eval(self): - """ + r""" Translate key to labels, if it is not already, expanding slices in the process. Returns @@ -811,7 +811,7 @@ def eval(self): raise NotImplementedError() def to_label(self): - """ + r""" Translate key to labels, if it is not already Returns @@ -821,7 +821,7 @@ def to_label(self): raise NotImplementedError() def retarget_to(self, target_axis): - """Retarget group to another axis. + r"""Retarget group to another axis. It will be translated to an LGroup using its former axis, if necessary. @@ -877,7 +877,7 @@ def __iter__(self): return iter([LGroup(v, axis=axis) for v in self.eval()]) def named(self, name): - """Returns group with a different name. + r"""Returns group with a different name. Parameters ---------- @@ -892,7 +892,7 @@ def named(self, name): __rshift__ = named def with_axis(self, axis): - """Returns group with a different axis. + r"""Returns group with a different axis. Parameters ---------- @@ -906,7 +906,7 @@ def with_axis(self, axis): return self.__class__(self.key, self.name, axis) def by(self, length, step=None, template=None): - """Split group into several groups of specified length. + r"""Split group into several groups of specified length. Parameters ---------- @@ -964,7 +964,7 @@ def make_group(start, length, name_template): # IGroup.i[] => IGroup # LGroup.i[] => IGroup def __getitem__(self, key): - """ + r""" Parameters ---------- @@ -1083,7 +1083,7 @@ def opmethod(self, other): __eq__ = _binop('eq') def equals(self, other): - """ + r""" Checks if this group is equal to another group. Two groups are equal if they have the same group and axis names and correspond to the same labels. @@ -1146,7 +1146,7 @@ def equals(self, other): return res if isinstance(res, bool) else all(res) def set(self): - """Creates LSet from this group + r"""Creates LSet from this group Returns ------- @@ -1155,7 +1155,7 @@ def set(self): return LSet(self.eval(), self.name, self.axis) def union(self, other): - """Returns (set) union of this label group and other. + r"""Returns (set) union of this label group and other. Labels relative order will be kept intact, but only unique labels will be returned. Labels from this group will be before labels from other. @@ -1183,7 +1183,7 @@ def union(self, other): return self.set().union(other) def intersection(self, other): - """Returns (set) intersection of this label group and other. + r"""Returns (set) intersection of this label group and other. In other words, this will return labels from this group which are also in other. Labels relative order will be kept intact, but only unique labels will be returned. @@ -1211,7 +1211,7 @@ def intersection(self, other): return self.set().intersection(other) def difference(self, other): - """Returns (set) difference of this label group and other. + r"""Returns (set) difference of this label group and other. In other words, this will return labels from this group without those in other. Labels relative order will be kept intact, but only unique labels will be returned. @@ -1244,7 +1244,7 @@ def __contains__(self, item): return item in self.eval() def startingwith(self, prefix): - """ + r""" Returns a group with the labels starting with the specified string. Parameters @@ -1272,7 +1272,7 @@ def startingwith(self, prefix): return LGroup([v for v in self.eval() if v.startswith(prefix)], axis=self.axis) def endingwith(self, suffix): - """ + r""" Returns a group with the labels ending with the specified string. Parameters @@ -1300,7 +1300,7 @@ def endingwith(self, suffix): return LGroup([v for v in self.eval() if v.endswith(suffix)], axis=self.axis) def matching(self, deprecated=None, pattern=None, regex=None): - """ + r""" Returns a group with all the labels matching the specified pattern or regular expression. Parameters @@ -1369,7 +1369,7 @@ def matching(self, deprecated=None, pattern=None, regex=None): return LGroup([v for v in self.eval() if match(v)], axis=self.axis) def containing(self, substring): - """ + r""" Returns a group with all the labels containing the specified substring. Parameters @@ -1397,7 +1397,7 @@ def containing(self, substring): return LGroup([v for v in self.eval() if substring in v], axis=self.axis) def to_hdf(self, filepath, key=None, axis_key=None): - """ + r""" Writes group to a HDF file. A HDF file can contain multiple groups. @@ -1537,7 +1537,7 @@ def remove_nested_groups(key): class LGroup(Group): - """Label group. + r"""Label group. Represents a subset of labels of an axis. @@ -1570,7 +1570,7 @@ def __init__(self, key, name=None, axis=None): # XXX: return IGroup instead? def translate(self, bound=None, stop=False): - """ + r""" compute position(s) of group """ if bound is None: @@ -1598,7 +1598,7 @@ def eval(self): class LSet(LGroup): - """Label set. + r"""Label set. Represents a set of (unique) labels of an axis. @@ -1670,7 +1670,7 @@ def opmethod(self, other): class IGroup(Group): - """Index Group. + r"""Index Group. Represents a subset of indices of an axis. @@ -1688,7 +1688,7 @@ class IGroup(Group): format_string = "{axis}.i[{key}]" def translate(self, bound=None, stop=False): - """ + r""" compute position(s) of group """ if bound is not None: diff --git a/larray/core/metadata.py b/larray/core/metadata.py index 76433b41c..c0d9f32b5 100644 --- a/larray/core/metadata.py +++ b/larray/core/metadata.py @@ -109,7 +109,7 @@ def __repr__(self): class Metadata(AttributeDict): - """ + r""" An ordered dictionary allowing key-values accessibly using attribute notation (AttributeDict.attribute) instead of key notation (Dict["key"]). diff --git a/larray/core/session.py b/larray/core/session.py index 5c1f59ecb..110c0d1e3 100644 --- a/larray/core/session.py +++ b/larray/core/session.py @@ -21,7 +21,7 @@ # XXX: inherit from OrderedDict or LArray? class Session(object): - """ + r""" Groups several objects together. Parameters @@ -105,7 +105,7 @@ def __iter__(self): return iter(self.values()) def add(self, *args, **kwargs): - """ + r""" Adds objects to the current session. Parameters @@ -260,7 +260,7 @@ def __getitem__(self, key): return self._objects[key] def get(self, key, default=None): - """ + r""" Returns the object corresponding to the key. If the key doesn't correspond to any object, a default one can be returned. @@ -287,13 +287,13 @@ def get(self, key, default=None): >>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)]) >>> arr = s.get('arr1') >>> arr - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 a2 6 7 8 >>> arr = s.get('arr4', zeros('a=a0,a1;b=b0,b1', dtype=int)) >>> arr - a\\b b0 b1 + a\b b0 b1 a0 0 0 a1 0 0 """ @@ -343,7 +343,7 @@ def __setstate__(self, d): object.__setattr__(self, '__dict__', d) def load(self, fname, names=None, engine='auto', display=False, **kwargs): - """ + r""" Load LArray, Axis and Group objects from a file, or several .csv files. WARNING: never load a file using the pickle engine (.pkl or .pickle) from an untrusted source, as it can lead @@ -430,7 +430,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs): self.meta = metadata def save(self, fname, names=None, engine='auto', overwrite=True, display=False, **kwargs): - """ + r""" Dumps LArray, Axis and Group objects from the current session to a file. Parameters @@ -499,7 +499,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False, handler.dump(meta, items, display=display, **kwargs) def to_globals(self, names=None, depth=0, warn=True, inplace=False): - """ + r""" Create global variables out of objects in the session. Parameters @@ -533,7 +533,7 @@ def to_globals(self, names=None, depth=0, warn=True, inplace=False): a a0 a1 a2 0 1 2 >>> arr2 - a\\b b0 b1 + a\b b0 b1 a0 0 1 a1 2 3 """ @@ -564,7 +564,7 @@ def to_globals(self, names=None, depth=0, warn=True, inplace=False): d[k] = v def to_pickle(self, fname, names=None, overwrite=True, display=False, **kwargs): - """ + r""" Dumps LArray, Axis and Group objects from the current session to a file using pickle. WARNING: never load a pickle file (.pkl or .pickle) from an untrusted source, as it can lead to arbitrary code @@ -609,7 +609,7 @@ def to_pickle(self, fname, names=None, overwrite=True, display=False, **kwargs): dump = renamed_to(save, 'dump') def to_hdf(self, fname, names=None, overwrite=True, display=False, **kwargs): - """ + r""" Dumps LArray, Axis and Group objects from the current session to an HDF file. Parameters @@ -651,7 +651,7 @@ def to_hdf(self, fname, names=None, overwrite=True, display=False, **kwargs): dump_hdf = renamed_to(to_hdf, 'dump_hdf') def to_excel(self, fname, names=None, overwrite=True, display=False, **kwargs): - """ + r""" Dumps LArray, Axis and Group objects from the current session to an Excel file. Parameters @@ -699,7 +699,7 @@ def to_excel(self, fname, names=None, overwrite=True, display=False, **kwargs): dump_excel = renamed_to(to_excel, 'dump_excel') def to_csv(self, fname, names=None, display=False, **kwargs): - """ + r""" Dumps LArray, Axis and Group objects from the current session to CSV files. Parameters @@ -745,7 +745,7 @@ def to_csv(self, fname, names=None, display=False, **kwargs): dump_csv = renamed_to(to_csv, 'dump_csv') def filter(self, pattern=None, kind=None): - """ + r""" Returns a new session with objects which match some criteria. Parameters @@ -801,7 +801,7 @@ def filter(self, pattern=None, kind=None): @property def names(self): - """ + r""" Returns the list of names of the objects in the session. The list is sorted alphabetically and does not follow the internal order. @@ -830,13 +830,13 @@ def names(self): return sorted(self._objects.keys()) def copy(self): - """Returns a copy of the session. + r"""Returns a copy of the session. """ # this actually *does* a copy of the internal mapping (the mapping is not reused-as is) return Session(self._objects) def keys(self): - """ + r""" Returns a view on the session's keys. Returns @@ -864,7 +864,7 @@ def keys(self): return self._objects.keys() def values(self): - """ + r""" Returns a view on the session's values. Returns @@ -882,7 +882,7 @@ def values(self): >>> # otherwise, prefer the following syntax >>> arr1, arr2, axis1, group1 = s['arr1', 'arr2', 'axis1', 'group1'] >>> arr1 - a\\b b0 b1 + a\b b0 b1 a0 0 1 a1 2 3 >>> axis1 @@ -891,7 +891,7 @@ def values(self): return self._objects.values() def items(self): - """ + r""" Returns a view of the session’s items ((key, value) pairs). Returns @@ -998,7 +998,7 @@ def opmethod(self): __invert__ = _unaryop('invert') def element_equals(self, other): - """Test if each element (group, axis and array) of the current session equals + r"""Test if each element (group, axis and array) of the current session equals the corresponding element of another session. For arrays, it is equivalent to apply :py:meth:`LArray.equals` with flag nans_equal=True @@ -1076,7 +1076,7 @@ def elem_equal(e1, e2): array_equals = renamed_to(element_equals, 'array_equals') def equals(self, other): - """Test if all elements (groups, axes and arrays) of the current session are equal + r"""Test if all elements (groups, axes and arrays) of the current session are equal to those of another session. Parameters @@ -1131,7 +1131,7 @@ def equals(self, other): return all(self.element_equals(other)) def transpose(self, *args): - """Reorder axes of arrays in session, ignoring missing axes for each array. + r"""Reorder axes of arrays in session, ignoring missing axes for each array. Parameters ---------- @@ -1185,7 +1185,7 @@ def lenient_transpose(v, axes): return self.apply(lenient_transpose, args) def compact(self, display=False): - """ + r""" Detects and removes "useless" axes (ie axes for which values are constant over the whole axis) for all array objects in session @@ -1203,7 +1203,7 @@ def compact(self, display=False): -------- >>> arr1 = sequence('b=b0..b2', ndtest(3), zeros_like(ndtest(3))) >>> arr1 - a\\b b0 b1 b2 + a\b b0 b1 b2 a0 0 0 0 a1 1 1 1 a2 2 2 2 @@ -1222,7 +1222,7 @@ def compact(self, display=False): return Session(new_items) def apply(self, func, *args, **kwargs): - """ + r""" Apply function `func` on elements of the session and return a new session. Parameters @@ -1402,7 +1402,7 @@ def _exclude_private_vars(vars_dict): def local_arrays(depth=0, include_private=False, meta=None): - """ + r""" Returns a session containing all local arrays sorted in alphabetical order. Parameters @@ -1427,7 +1427,7 @@ def local_arrays(depth=0, include_private=False, meta=None): def global_arrays(depth=0, include_private=False, meta=None): - """ + r""" Returns a session containing all global arrays sorted in alphabetical order. Parameters @@ -1452,7 +1452,7 @@ def global_arrays(depth=0, include_private=False, meta=None): def arrays(depth=0, include_private=False, meta=None): - """ + r""" Returns a session containing all available arrays (whether they are defined in local or global variables) sorted in alphabetical order. Local arrays take precedence over global ones (if a name corresponds to both a local and a global variable, the local array will be returned). diff --git a/larray/example.py b/larray/example.py index 302b74be8..f398c76b3 100644 --- a/larray/example.py +++ b/larray/example.py @@ -10,7 +10,7 @@ def get_example_filepath(fname): - """Return absolute path to an example file if exist. + r"""Return absolute path to an example file if exist. Parameters ---------- @@ -38,7 +38,7 @@ def get_example_filepath(fname): def load_example_data(name): - """Load arrays used in the tutorial so that all examples in it can be reproduced. + r"""Load arrays used in the tutorial so that all examples in it can be reproduced. Parameters ---------- diff --git a/larray/extra/ipfp.py b/larray/extra/ipfp.py index 83769a01b..774aad97b 100644 --- a/larray/extra/ipfp.py +++ b/larray/extra/ipfp.py @@ -12,7 +12,7 @@ def badvalues(a, bad_filter): def f2str(f, threshold=2): - """Return string representation of floating point number f. + r"""Return string representation of floating point number f. Use scientific notation if f would have more than threshold decimal digits, otherwise use threshold as precision. Parameters @@ -45,7 +45,7 @@ def warn_or_raise(what, msg): def ipfp(target_sums, a=None, axes=None, maxiter=1000, threshold=0.5, stepstoabort=10, nzvzs='raise', no_convergence='raise', display_progress=False): - """Apply Iterative Proportional Fitting Procedure (also known as bi-proportional fitting in statistics, + r"""Apply Iterative Proportional Fitting Procedure (also known as bi-proportional fitting in statistics, RAS algorithm in economics) to array a, with target_sums as targets. Parameters @@ -90,7 +90,7 @@ def ipfp(target_sums, a=None, axes=None, maxiter=1000, threshold=0.5, stepstoabo >>> b = Axis('b=b0,b1') >>> initial = LArray([[2, 1], [1, 2]], [a, b]) >>> initial - a\\b b0 b1 + a\b b0 b1 a0 2 1 a1 1 2 >>> target_sum_along_a = LArray([2, 1], b) @@ -104,7 +104,7 @@ def ipfp(target_sums, a=None, axes=None, maxiter=1000, threshold=0.5, stepstoabo >>> result = ipfp([target_sum_along_a, target_sum_along_b], initial, threshold=0.01) >>> # round result so that its display is nicer ... round(result, 2) - a\\b b0 b1 + a\b b0 b1 a0 0.85 0.15 a1 1.15 0.85 diff --git a/larray/inout/common.py b/larray/inout/common.py index b3efaf915..fd0fe3cb8 100644 --- a/larray/inout/common.py +++ b/larray/inout/common.py @@ -22,7 +22,7 @@ def _get_index_col(nb_axes=None, index_col=None, wide=True): class FileHandler(object): - """ + r""" Abstract class defining the methods for "file handler" subclasses. Parameters @@ -47,35 +47,35 @@ def _open_for_write(self): raise NotImplementedError() def list_items(self): - """ + r""" Return list containing pairs (name, type) for all stored objects """ raise NotImplementedError() def _read_item(self, key, type, *args, **kwargs): - """Read item""" + r"""Read item""" raise NotImplementedError() def _read_metadata(self): - """Read metadata""" + r"""Read metadata""" raise NotImplementedError() def _dump_item(self, key, value, *args, **kwargs): - """Dump item. Raises an TypeError if type not taken into account by the FileHandler subclass.""" + r"""Dump item. Raises an TypeError if type not taken into account by the FileHandler subclass.""" raise NotImplementedError() def _dump_metadata(self, metadata): - """Dump metadata""" + r"""Dump metadata""" raise NotImplementedError() def save(self): - """ + r""" Saves items in file. """ pass def close(self): - """ + r""" Closes file. """ raise NotImplementedError() @@ -91,7 +91,7 @@ def _update_original_file(self): os.rename(self.fname, self.original_file_name) def read(self, keys, *args, **kwargs): - """ + r""" Reads file content (HDF, Excel, CSV, ...) and returns a dictionary containing loaded objects. Parameters @@ -137,7 +137,7 @@ def read(self, keys, *args, **kwargs): return metadata, res def dump(self, metadata, key_values, *args, **kwargs): - """ + r""" Dumps objects corresponding to keys in file in HDF, Excel, CSV, ... format Parameters diff --git a/larray/inout/csv.py b/larray/inout/csv.py index 0f89b736b..440771afe 100644 --- a/larray/inout/csv.py +++ b/larray/inout/csv.py @@ -238,7 +238,7 @@ def read_tsv(filepath_or_buffer, **kwargs): def read_eurostat(filepath_or_buffer, **kwargs): - """Reads EUROSTAT TSV (tab-separated) file into an array. + r"""Reads EUROSTAT TSV (tab-separated) file into an array. EUROSTAT TSV files are special because they use tabs as data separators but comas to separate headers. diff --git a/larray/inout/excel.py b/larray/inout/excel.py index 69417bb33..d7d7cfff8 100644 --- a/larray/inout/excel.py +++ b/larray/inout/excel.py @@ -226,7 +226,7 @@ def read_excel(filepath, sheet=0, nb_axes=None, index_col=None, fill_value=nan, @register_file_handler('pandas_excel', ['xls', 'xlsx'] if xw is None else None) class PandasExcelHandler(FileHandler): - """ + r""" Handler for Excel files using Pandas. """ def __init__(self, fname, overwrite_file=False): @@ -328,7 +328,7 @@ def close(self): @register_file_handler('xlwings_excel', ['xls', 'xlsx'] if xw is not None else None) class XLWingsHandler(FileHandler): - """ + r""" Handler for Excel files using XLWings. """ def __init__(self, fname, overwrite_file=False): diff --git a/larray/inout/hdf.py b/larray/inout/hdf.py index 025498add..4e8f32b7d 100644 --- a/larray/inout/hdf.py +++ b/larray/inout/hdf.py @@ -19,7 +19,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, sort_columns=False, name=None, **kwargs): - """Reads an axis or group or array named key from a HDF5 file in filepath (path+name) + r"""Reads an axis or group or array named key from a HDF5 file in filepath (path+name) Parameters ---------- @@ -54,7 +54,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s >>> # The data below is derived from a subset of the demo_pjan table from Eurostat >>> read_hdf(fname, 'pop') - country gender\\time 2013 2014 2015 + country gender\time 2013 2014 2015 Belgium Male 5472856 5493792 5524068 Belgium Female 5665118 5687048 5713206 France Male 31772665 31936596 32175328 @@ -102,7 +102,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s @register_file_handler('pandas_hdf', ['h5', 'hdf']) class PandasHDFHandler(FileHandler): - """ + r""" Handler for HDF5 files using Pandas. """ def _open_for_read(self): diff --git a/larray/inout/misc.py b/larray/inout/misc.py index 5ca6438b9..ec3e04e59 100644 --- a/larray/inout/misc.py +++ b/larray/inout/misc.py @@ -12,7 +12,7 @@ @deprecate_kwarg('nb_index', 'nb_axes', arg_converter=lambda x: x + 1) def from_lists(data, nb_axes=None, index_col=None, fill_value=nan, sort_rows=False, sort_columns=False, wide=True): - """ + r""" initialize array from a list of lists (lines) Parameters @@ -49,30 +49,30 @@ def from_lists(data, nb_axes=None, index_col=None, fill_value=nan, sort_rows=Fal ... ['', 0, 1]]) sex M F 0 1 - >>> from_lists([['sex\\\\year', 1991, 1992, 1993], + >>> from_lists([['sex\\year', 1991, 1992, 1993], ... [ 'M', 0, 1, 2], ... [ 'F', 3, 4, 5]]) - sex\\year 1991 1992 1993 + sex\year 1991 1992 1993 M 0 1 2 F 3 4 5 Read array with missing values + `fill_value` argument - >>> from_lists([['sex', 'nat\\\\year', 1991, 1992, 1993], + >>> from_lists([['sex', 'nat\\year', 1991, 1992, 1993], ... [ 'M', 'BE', 1, 0, 0], ... [ 'M', 'FO', 2, 0, 0], ... [ 'F', 'BE', 0, 0, 1]]) - sex nat\\year 1991 1992 1993 + sex nat\year 1991 1992 1993 M BE 1.0 0.0 0.0 M FO 2.0 0.0 0.0 F BE 0.0 0.0 1.0 F FO nan nan nan - >>> from_lists([['sex', 'nat\\\\year', 1991, 1992, 1993], + >>> from_lists([['sex', 'nat\\year', 1991, 1992, 1993], ... [ 'M', 'BE', 1, 0, 0], ... [ 'M', 'FO', 2, 0, 0], ... [ 'F', 'BE', 0, 0, 1]], fill_value=42) - sex nat\\year 1991 1992 1993 + sex nat\year 1991 1992 1993 M BE 1 0 0 M FO 2 0 0 F BE 0 0 1 @@ -84,7 +84,7 @@ def from_lists(data, nb_axes=None, index_col=None, fill_value=nan, sort_rows=Fal ... [ 'M', 'BE', 1, 0, 0], ... [ 'M', 'FO', 2, 0, 0], ... [ 'F', 'BE', 0, 0, 1]], nb_axes=3) - sex nat\\{2} 1991 1992 1993 + sex nat\{2} 1991 1992 1993 M BE 1.0 0.0 0.0 M FO 2.0 0.0 0.0 F BE 0.0 0.0 1.0 @@ -102,7 +102,7 @@ def from_lists(data, nb_axes=None, index_col=None, fill_value=nan, sort_rows=Fal ... [ 'F', 'BE', 1991, 0 ], ... [ 'F', 'BE', 1992, 0 ], ... [ 'F', 'BE', 1993, 1 ]], wide=False) - sex nat\\year 1991 1992 1993 + sex nat\year 1991 1992 1993 M BE 1.0 0.0 0.0 M FO 2.0 0.0 0.0 F BE 0.0 0.0 1.0 @@ -139,7 +139,7 @@ def from_string(s, nb_axes=None, index_col=None, sep=' ', wide=True, **kwargs): Whether or not to assume the array is stored in "wide" format. If False, the array is assumed to be stored in "narrow" format: one column per axis plus one value column. Defaults to True. - \**kwargs + **kwargs See arguments of Pandas read_csv function. Returns diff --git a/larray/inout/pandas.py b/larray/inout/pandas.py index c21887807..a9732f4c0 100644 --- a/larray/inout/pandas.py +++ b/larray/inout/pandas.py @@ -14,7 +14,7 @@ def parse(s): - """ + r""" Used to parse the "folded" axis ticks (usually periods). """ # parameters can be strings or numbers @@ -37,7 +37,7 @@ def parse(s): def index_to_labels(idx, sort=True): - """ + r""" Returns unique labels for each dimension. """ if isinstance(idx, pd.core.index.MultiIndex): @@ -254,7 +254,7 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo def df_aslarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header=True, wide=True, cartesian_prod=True, **kwargs): - """ + r""" Prepare Pandas DataFrame and then convert it into LArray. Parameters diff --git a/larray/inout/sas.py b/larray/inout/sas.py index be8fb3fa7..585b6f20f 100644 --- a/larray/inout/sas.py +++ b/larray/inout/sas.py @@ -13,7 +13,7 @@ @deprecate_kwarg('nb_index', 'nb_axes', arg_converter=lambda x: x + 1) def read_sas(filepath, nb_axes=None, index_col=None, fill_value=nan, na=nan, sort_rows=False, sort_columns=False, **kwargs): - """ + r""" Reads sas file and returns an LArray with the contents nb_axes: number of axes of the output array or diff --git a/larray/inout/session.py b/larray/inout/session.py index 59d472bc5..406e2355f 100644 --- a/larray/inout/session.py +++ b/larray/inout/session.py @@ -7,7 +7,7 @@ def register_file_handler(engine, extensions=None): - """Class decorator to register new file handler class + r"""Class decorator to register new file handler class Parameters ---------- diff --git a/larray/inout/xw_excel.py b/larray/inout/xw_excel.py index 6575ea2d1..9bd57b02b 100644 --- a/larray/inout/xw_excel.py +++ b/larray/inout/xw_excel.py @@ -327,7 +327,7 @@ def __repr__(self): def _fill_slice(s, length): - """ + r""" replaces a slice None bounds by actual bounds. Parameters @@ -345,7 +345,7 @@ def _fill_slice(s, length): def _concrete_key(key, obj, ndim=2): - """Expand key to ndim and replace None in slices start/stop bounds by 0 or obj.shape[corresponding_dim] + r"""Expand key to ndim and replace None in slices start/stop bounds by 0 or obj.shape[corresponding_dim] respectively. Parameters @@ -403,7 +403,7 @@ def __setitem__(self, key, value): @property def shape(self): - """ + r""" shape of sheet including top-left empty rows/columns but excluding bottom-right ones. """ from xlwings.constants import Direction as xldir @@ -485,7 +485,7 @@ def load(self, header=True, convert_float=True, nb_axes=None, index_col=None, fi # TODO: generalize to more than 2 dimensions or scrap it def array(self, data, row_labels=None, column_labels=None, names=None): - """ + r""" Parameters ---------- @@ -649,7 +649,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a # We define Workbook and open_excel documentation here since Readthedocs runs on Linux if not PY2: - Workbook.__doc__ = """ + Workbook.__doc__ = r""" Excel Workbook. See Also @@ -657,7 +657,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a open_excel """ - Workbook.sheet_names.__doc__ = """ + Workbook.sheet_names.__doc__ = r""" Returns the names of the Excel sheets. Examples @@ -673,7 +673,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a ['arr', 'arr2', 'arr3'] """ - Workbook.save.__doc__ = """ + Workbook.save.__doc__ = r""" Saves the Workbook. If a path is being provided, this works like SaveAs() in Excel. @@ -696,7 +696,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a ... wb.save() """ - Workbook.close.__doc__ = """ + Workbook.close.__doc__ = r""" Close the workbook in Excel. Need to be called if the workbook has been opened without the `with` statement. @@ -712,11 +712,11 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a >>> wb.close() # doctest: +SKIP """ - Workbook.app.__doc__ = """ + Workbook.app.__doc__ = r""" Return the Excel instance this workbook is attached to. """ -open_excel.__doc__ = """ +open_excel.__doc__ = r""" Open an Excel workbook Parameters @@ -750,7 +750,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a -------- >>> arr = ndtest((3, 3)) >>> arr -a\\b b0 b1 b2 +a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 a2 6 7 8 @@ -767,7 +767,7 @@ def open_excel(filepath=None, overwrite_file=False, visible=None, silent=None, a >>> with open_excel('excel_file.xlsx') as wb: # doctest: +SKIP ... arr2 = wb['arr'].load() >>> arr2 # doctest: +SKIP -a\\b b0 b1 b2 +a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 a2 6 7 8 diff --git a/larray/util/options.py b/larray/util/options.py index 5e0a52e64..b74d9020b 100644 --- a/larray/util/options.py +++ b/larray/util/options.py @@ -112,7 +112,7 @@ def __exit__(self, type, value, traceback): def get_options(): - """ + r""" Return the current options. Returns diff --git a/larray/viewer/__init__.py b/larray/viewer/__init__.py index 4156f4b1f..e8a69f478 100644 --- a/larray/viewer/__init__.py +++ b/larray/viewer/__init__.py @@ -2,7 +2,7 @@ def view(obj=None, title='', depth=0): - """ + r""" Opens a new viewer window. Arrays are loaded in readonly mode and their content cannot be modified. Parameters @@ -35,7 +35,7 @@ def view(obj=None, title='', depth=0): def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth=0): - """ + r""" Opens a new editor window. Parameters @@ -76,7 +76,7 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth def compare(*args, **kwargs): - """ + r""" Opens a new comparator window, comparing arrays or sessions. Parameters