Skip to content

Commit c3b32c0

Browse files
committed
added dtype argument to stack to set the type of the resulting array explicitly instead of relying on auto-detection, which can be slow
1 parent cd9addf commit c3b32c0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/source/changes/version_0_30.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ Miscellaneous improvements
224224

225225
* added dtype argument to LArray to set the type of the array explicitly instead of relying on auto-detection.
226226

227+
* added dtype argument to stack to set the type of the resulting array explicitly instead of relying on auto-detection.
228+
227229
* implemented :py:obj:`LArray.reverse()` method to reverse one or several axes of an array (closes :issue:`631`).
228230

229231
* added :py:obj:`set_options` allowing to set options for larray within a ``with`` block or globally:

larray/core/array.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8268,7 +8268,7 @@ def eye(rows, columns=None, k=0, title=None, dtype=None, meta=None):
82688268
# ('DE', 'M'): 4, ('DE', 'F'): 5})
82698269

82708270

8271-
def stack(elements=None, axis=None, title=None, meta=None, **kwargs):
8271+
def stack(elements=None, axis=None, title=None, meta=None, dtype=None, **kwargs):
82728272
r"""
82738273
Combines several arrays or sessions along an axis.
82748274
@@ -8288,6 +8288,8 @@ def stack(elements=None, axis=None, title=None, meta=None, **kwargs):
82888288
meta : list of pairs or dict or OrderedDict or Metadata, optional
82898289
Metadata (title, description, author, creation_date, ...) associated with the array.
82908290
Keys must be strings. Values must be of type string, int, float, date, time or datetime.
8291+
dtype : type, optional
8292+
Output dtype. Defaults to None (inspect all output values to infer it automatically).
82918293
82928294
Returns
82938295
-------
@@ -8465,7 +8467,9 @@ def stack(elements=None, axis=None, title=None, meta=None, **kwargs):
84658467
for v in values]
84668468
result_axes = AxisCollection.union(*[get_axes(v) for v in values])
84678469
result_axes.append(axis)
8468-
result = empty(result_axes, dtype=common_type(values), meta=meta)
8470+
if dtype is None:
8471+
dtype = common_type(values)
8472+
result = empty(result_axes, dtype=dtype, meta=meta)
84698473
for k, v in zip(axis, values):
84708474
result[k] = v
84718475
return result

0 commit comments

Comments
 (0)