Skip to content

Commit

Permalink
MAINT: make __str__ less ambiguous
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ev-br committed Dec 25, 2024
1 parent e4b6bfe commit 488c733
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__.
Expand All @@ -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
Expand Down

0 comments on commit 488c733

Please # to comment.