From 488c7336dba8195347007a852873b52e0b821d62 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Wed, 25 Dec 2024 18:32:52 +0200 Subject: [PATCH] MAINT: make __str__ less ambiguous For 0D arrays, __str__ used to look like a scalar: In [2]: x = xp.asarray(3) In [3]: print(x) 3 So make it clearly an array. --- array_api_strict/_array_object.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/array_api_strict/_array_object.py b/array_api_strict/_array_object.py index 0de6b8a..a917441 100644 --- a/array_api_strict/_array_object.py +++ b/array_api_strict/_array_object.py @@ -126,12 +126,6 @@ def __new__(cls, *args, **kwargs): # These functions are not required by the spec, but are implemented for # the sake of usability. - def __str__(self: Array, /) -> str: - """ - Performs the operation __str__. - """ - return self._array.__str__().replace("array", "Array") - def __repr__(self: Array, /) -> str: """ Performs the operation __repr__. @@ -149,6 +143,8 @@ def __repr__(self: Array, /) -> str: mid = np.array2string(self._array, separator=', ', prefix=prefix, suffix=suffix) return prefix + mid + suffix + __str__ = __repr__ + # In the future, _allow_array will be set to False, which will disallow # __array__. This means calling `np.func()` on an array_api_strict array # will give an error. If we don't explicitly disallow it, NumPy defaults