Skip to content

Commit cd762d7

Browse files
committed
renamed the aslarray() function to asarray()
1 parent 86bc065 commit cd762d7

File tree

14 files changed

+50
-47
lines changed

14 files changed

+50
-47
lines changed

doc/source/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ Miscellaneous
714714
.. autosummary::
715715
:toctree: _generated/
716716

717-
aslarray
717+
asarray
718718
from_frame
719719
from_series
720720
get_example_filepath

doc/source/tutorial/pandas.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ To convert an Array object into a pandas DataFrame, the method :py:meth:`~Array.
88
df = pop.to_frame()
99
df
1010
11-
Inversely, to convert a DataFrame into an Array object, use the function :py:func:`aslarray`:
11+
Inversely, to convert a DataFrame into an Array object, use the function :py:func:`asarray`:
1212

1313
.. ipython:: python
1414
15-
pop = aslarray(df)
15+
pop = asarray(df)
1616
pop

larray/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from larray.core.axis import Axis, AxisCollection, X
77
from larray.core.group import Group, LGroup, LSet, IGroup, union
88
from larray.core.array import (Array, zeros, zeros_like, ones, ones_like, empty, empty_like, full,
9-
full_like, sequence, labels_array, ndtest, aslarray, identity, diag,
9+
full_like, sequence, labels_array, ndtest, asarray, identity, diag,
1010
eye, all, any, sum, prod, cumsum, cumprod, min, max, mean, ptp, var,
1111
std, median, percentile, stack, zip_array_values, zip_array_items)
1212
from larray.core.session import Session, local_arrays, global_arrays, arrays
@@ -54,7 +54,7 @@
5454
'Group', 'LGroup', 'LSet', 'IGroup', 'union',
5555
# array
5656
'Array', 'zeros', 'zeros_like', 'ones', 'ones_like', 'empty', 'empty_like', 'full',
57-
'full_like', 'sequence', 'labels_array', 'ndtest', 'aslarray', 'identity', 'diag', 'eye',
57+
'full_like', 'sequence', 'labels_array', 'ndtest', 'asarray', 'identity', 'diag', 'eye',
5858
'all', 'any', 'sum', 'prod', 'cumsum', 'cumprod', 'min', 'max', 'mean', 'ptp', 'var', 'std',
5959
'median', 'percentile', 'stack',
6060
# session
@@ -93,8 +93,8 @@
9393

9494
from larray.core.axis import x
9595
from larray.core.group import PGroup
96-
from larray.core.array import (LArray, create_sequential, ndrange, larray_equal, larray_nan_equal,
97-
nan_equal, element_equal)
96+
from larray.core.array import (LArray, aslarray, create_sequential, ndrange, larray_equal,
97+
larray_nan_equal, nan_equal, element_equal)
9898

9999

100100
_deprecated = [
@@ -103,7 +103,7 @@
103103
# group
104104
'PGroup',
105105
# array
106-
'LArray',
106+
'LArray', 'aslarray',
107107
'create_sequential', 'ndrange',
108108
'larray_equal', 'larray_nan_equal', 'nan_equal', 'element_equal',
109109
]

larray/core/array.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def element_equal(a1, a2, rtol=0, atol=0, nan_equals=False):
671671
import warnings
672672
warnings.warn("element_equal() is deprecated. Use array1.eq(array2, rtol, atol, nan_equals) instead.",
673673
FutureWarning, stacklevel=2)
674-
a1 = aslarray(a1)
674+
a1 = asarray(a1)
675675
return a1.eq(a2, rtol, atol, nan_equals)
676676

677677

@@ -704,7 +704,7 @@ class Array(ABCArray):
704704
r"""
705705
An Array object represents a multidimensional, homogeneous array of fixed-size items with labeled axes.
706706
707-
The function :func:`aslarray` can be used to convert a NumPy array or Pandas DataFrame into an Array.
707+
The function :func:`asarray` can be used to convert a NumPy array or Pandas DataFrame into an Array.
708708
709709
Parameters
710710
----------
@@ -1810,7 +1810,7 @@ def align(self, other, join='outer', fill_value=nan, axes=None):
18101810
ValueError: Both arrays are not aligned because align method with join='exact'
18111811
expected Axis(['a0', 'a1'], 'a') to be equal to Axis(['a0', 'a1', 'a2'], 'a')
18121812
"""
1813-
other = aslarray(other)
1813+
other = asarray(other)
18141814
# reindex does not currently support anonymous axes
18151815
if any(name is None for name in self.axes.names) or any(name is None for name in other.axes.names):
18161816
raise ValueError("arrays with anonymous axes are currently not supported by Array.align")
@@ -5482,12 +5482,12 @@ def opmethod(self, other):
54825482
if isinstance(other, Group) and np.isscalar(other.key):
54835483
other = other.eval()
54845484

5485-
# we could pass scalars through aslarray too but it is too costly performance-wise for only suppressing one
5485+
# we could pass scalars through asarray too but it is too costly performance-wise for only suppressing one
54865486
# isscalar test and an if statement.
54875487
# TODO: ndarray should probably be converted to larrays because that would harmonize broadcasting rules, but
54885488
# it makes some tests fail for some reason.
54895489
if not isinstance(other, (Array, np.ndarray)) and not np.isscalar(other):
5490-
other = aslarray(other)
5490+
other = asarray(other)
54915491

54925492
if isinstance(other, Array):
54935493
# TODO: first test if it is not already broadcastable
@@ -5662,7 +5662,7 @@ def equals(self, other, rtol=0, atol=0, nans_equal=False, check_axes=False):
56625662
Parameters
56635663
----------
56645664
other : Array-like
5665-
Input array. aslarray() is used on a non-Array input.
5665+
Input array. asarray() is used on a non-Array input.
56665666
rtol : float or int, optional
56675667
The relative tolerance parameter (see Notes). Defaults to 0.
56685668
atol : float or int, optional
@@ -5777,7 +5777,7 @@ def equals(self, other, rtol=0, atol=0, nans_equal=False, check_axes=False):
57775777
False
57785778
"""
57795779
try:
5780-
other = aslarray(other)
5780+
other = asarray(other)
57815781
except Exception:
57825782
return False
57835783
try:
@@ -5794,7 +5794,7 @@ def eq(self, other, rtol=0, atol=0, nans_equal=False):
57945794
Parameters
57955795
----------
57965796
other : Array-like
5797-
Input array. aslarray() is used on a non-Array input.
5797+
Input array. asarray() is used on a non-Array input.
57985798
rtol : float or int, optional
57995799
The relative tolerance parameter (see Notes). Defaults to 0.
58005800
atol : float or int, optional
@@ -5855,7 +5855,7 @@ def eq(self, other, rtol=0, atol=0, nans_equal=False):
58555855
a a0 a1 a2
58565856
True True True
58575857
"""
5858-
other = aslarray(other)
5858+
other = asarray(other)
58595859

58605860
if rtol == 0 and atol == 0:
58615861
if not nans_equal:
@@ -6406,7 +6406,7 @@ def expand(v, length):
64066406
values = [value[[k]] for k in value.axes[axis]]
64076407
else:
64086408
values = expand(value, num_inserts)
6409-
values = [aslarray(v) if not isinstance(v, Array) else v
6409+
values = [asarray(v) if not isinstance(v, Array) else v
64106410
for v in values]
64116411

64126412
if label is not None:
@@ -8038,7 +8038,7 @@ def larray_equal(a1, a2):
80388038
msg = "larray_equal() is deprecated. Use Array.equals() instead."
80398039
warnings.warn(msg, FutureWarning, stacklevel=2)
80408040
try:
8041-
a1 = aslarray(a1)
8041+
a1 = asarray(a1)
80428042
except Exception:
80438043
return False
80448044
return a1.equals(a2)
@@ -8049,13 +8049,13 @@ def larray_nan_equal(a1, a2):
80498049
msg = "larray_nan_equal() is deprecated. Use Array.equals() instead."
80508050
warnings.warn(msg, FutureWarning, stacklevel=2)
80518051
try:
8052-
a1 = aslarray(a1)
8052+
a1 = asarray(a1)
80538053
except Exception:
80548054
return False
80558055
return a1.equals(a2, nans_equal=True)
80568056

80578057

8058-
def aslarray(a, meta=None):
8058+
def asarray(a, meta=None):
80598059
r"""
80608060
Converts input as Array if possible.
80618061
@@ -8075,15 +8075,15 @@ def aslarray(a, meta=None):
80758075
--------
80768076
>>> # NumPy array
80778077
>>> np_arr = np.arange(6).reshape((2,3))
8078-
>>> aslarray(np_arr)
8078+
>>> asarray(np_arr)
80798079
{0}*\{1}* 0 1 2
80808080
0 0 1 2
80818081
1 3 4 5
80828082
>>> # Pandas dataframe
80838083
>>> data = {'normal' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
80848084
... 'reverse' : pd.Series([3., 2., 1.], index=['a', 'b', 'c'])}
80858085
>>> df = pd.DataFrame(data)
8086-
>>> aslarray(df)
8086+
>>> asarray(df)
80878087
{0}\{1} normal reverse
80888088
a 1.0 3.0
80898089
b 2.0 2.0
@@ -8108,6 +8108,9 @@ def aslarray(a, meta=None):
81088108
return Array(a, meta=meta)
81098109

81108110

8111+
aslarray = renamed_to(asarray, 'aslarray')
8112+
8113+
81118114
def _check_axes_argument(func):
81128115
@functools.wraps(func)
81138116
def wrapper(*args, **kwargs):
@@ -9319,7 +9322,7 @@ def stack_one(array_name):
93199322
return Session([(array_name, stack_one(array_name)) for array_name in array_names], meta=meta)
93209323
else:
93219324
if res_axes is None or dtype is None:
9322-
values = [aslarray(v) if not np.isscalar(v) else v
9325+
values = [asarray(v) if not np.isscalar(v) else v
93239326
for k, v in items]
93249327

93259328
if res_axes is None:

larray/core/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,9 +3451,9 @@ def _flat_lookup(self, flat_indices):
34513451
d1 a1 b2
34523452
d2 a0 b0
34533453
"""
3454-
from larray.core.array import aslarray, Array, stack
3454+
from larray.core.array import asarray, Array, stack
34553455

3456-
flat_indices = aslarray(flat_indices)
3456+
flat_indices = asarray(flat_indices)
34573457
axes_indices = np.unravel_index(flat_indices, self.shape)
34583458
# This could return an Array with object dtype because axes labels can have different types (but not length)
34593459
# TODO: this should be:

larray/core/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def __larray__(self):
148148

149149
@classmethod
150150
def from_array(cls, array):
151-
from larray.core.array import aslarray
152-
array = aslarray(array)
151+
from larray.core.array import asarray
152+
array = asarray(array)
153153
if array.ndim != 1:
154154
raise ValueError("Expected Array object of dimension 1. Got array of dimension {}".format(array.ndim))
155155

larray/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from larray.core.group import Group
1515
from larray.core.axis import Axis
1616
from larray.core.constants import nan
17-
from larray.core.array import Array, get_axes, ndtest, zeros, zeros_like, sequence, aslarray
17+
from larray.core.array import Array, get_axes, ndtest, zeros, zeros_like, sequence, asarray
1818
from larray.util.misc import float_error_handler_factory, is_interactive_interpreter, renamed_to, inverseop, basestring
1919
from larray.inout.session import ext_default_engine, get_file_handler
2020

larray/extra/ipfp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
from collections import deque
33

4-
from larray.core.array import Array, aslarray, ones, any
4+
from larray.core.array import Array, asarray, ones, any
55
import numpy as np
66

77

@@ -142,7 +142,7 @@ def ipfp(target_sums, a=None, axes=None, maxiter=1000, threshold=0.5, stepstoabo
142142
assert no_convergence in {'ignore', 'warn', 'raise'}
143143
assert isinstance(display_progress, bool) or display_progress == 'condensed'
144144

145-
target_sums = [aslarray(ts) for ts in target_sums]
145+
target_sums = [asarray(ts) for ts in target_sums]
146146

147147
n = len(target_sums)
148148

@@ -189,7 +189,7 @@ def has_anonymous_axes(a):
189189
if nzvzs in {'warn', 'fix'} and isinstance(a, Array):
190190
a = a.copy()
191191
else:
192-
a = aslarray(a)
192+
a = asarray(a)
193193
# TODO: this should be a builtin op
194194
a = a.rename({i: name if name is not None else 'axis{}'.format(i)
195195
for i, name in enumerate(a.axes.names)})

larray/inout/csv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pandas as pd
1010
import numpy as np
1111

12-
from larray.core.array import Array, aslarray, ndtest
12+
from larray.core.array import Array, asarray, ndtest
1313
from larray.core.axis import Axis
1414
from larray.core.constants import nan
1515
from larray.core.group import Group
@@ -370,7 +370,7 @@ def _read_metadata(self):
370370

371371
def _dump_metadata(self, metadata):
372372
if len(metadata) > 0:
373-
meta = aslarray(metadata)
373+
meta = asarray(metadata)
374374
meta.to_csv(self._to_filepath('__metadata__'), sep=self.sep, wide=False, value_name='')
375375

376376
def save(self):

larray/inout/excel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
except ImportError:
1212
xw = None
1313

14-
from larray.core.array import Array, aslarray
14+
from larray.core.array import Array, asarray
1515
from larray.core.axis import Axis
1616
from larray.core.constants import nan
1717
from larray.core.group import Group, _translate_sheet_name
@@ -311,7 +311,7 @@ def _read_metadata(self):
311311

312312
def _dump_metadata(self, metadata):
313313
if len(metadata) > 0:
314-
metadata = aslarray(metadata)
314+
metadata = asarray(metadata)
315315
metadata.to_excel(self.handle, '__metadata__', engine='xlsxwriter', wide=False, value_name='')
316316

317317
def save(self):
@@ -414,7 +414,7 @@ def _read_metadata(self):
414414

415415
def _dump_metadata(self, metadata):
416416
if len(metadata) > 0:
417-
metadata = aslarray(metadata)
417+
metadata = asarray(metadata)
418418
self.handle['__metadata__'] = metadata.dump(wide=False, value_name='')
419419

420420
def save(self):

0 commit comments

Comments
 (0)