Skip to content

Commit 85cfbd4

Browse files
committed
FIX: fixed converting a scalar Array (an Array with 0 dimensions) to string with numpy 1.23+
this was deprecated from numpy 1.16, but this escaped our radar because our test was buggy
1 parent 2835d2a commit 85cfbd4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

doc/source/changes/version_0_34_3.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ Fixes
5656
^^^^^
5757

5858
* fixed something (closes :issue:`1`).
59+
60+
* fixed converting a scalar Array (an Array with 0 dimensions) to string with numpy 1.22+.

larray/core/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,9 +2446,9 @@ def ignore_labels(self, axes=None) -> 'Array':
24462446
drop_labels = renamed_to(ignore_labels, 'drop_labels', raise_error=True)
24472447

24482448
def __str__(self) -> str:
2449-
if not self.ndim:
2450-
return str(np.asscalar(self))
2451-
elif not len(self):
2449+
if self.ndim == 0:
2450+
return str(self.data.item())
2451+
elif len(self) == 0:
24522452
return 'Array([])'
24532453
else:
24542454
table = self.dump(maxlines=_OPTIONS[DISPLAY_MAXLINES], edgeitems=_OPTIONS[DISPLAY_EDGEITEMS],

larray/tests/test_array.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,9 @@ def test_info(array, meta):
435435
def test_str(small_array, array):
436436
d3 = d['d1:d3']
437437

438-
# zero dimension / scalar
439-
assert str(small_array[d['d1'], c['c1']]) == "6"
438+
# zero dimension / scalar Array
439+
scalar_array = Array(42)
440+
assert str(scalar_array) == "42"
440441

441442
# empty / len 0 first dimension
442443
assert str(small_array[c[[]]]) == "Array([])"

0 commit comments

Comments
 (0)