@@ -1727,78 +1727,3 @@ def array_str(a, max_line_width=None, precision=None, suppress_small=None):
1727
1727
array2string = _array2string_impl )
1728
1728
_default_array_repr = functools .partial (_array_repr_implementation ,
1729
1729
array2string = _array2string_impl )
1730
-
1731
-
1732
- def set_string_function (f , repr = True ):
1733
- """
1734
- Set a Python function to be used when pretty printing arrays.
1735
-
1736
- .. deprecated:: 2.0
1737
- Use `np.set_printoptions` instead with a formatter for custom
1738
- printing of NumPy objects.
1739
-
1740
- Parameters
1741
- ----------
1742
- f : function or None
1743
- Function to be used to pretty print arrays. The function should expect
1744
- a single array argument and return a string of the representation of
1745
- the array. If None, the function is reset to the default NumPy function
1746
- to print arrays.
1747
- repr : bool, optional
1748
- If True (default), the function for pretty printing (``__repr__``)
1749
- is set, if False the function that returns the default string
1750
- representation (``__str__``) is set.
1751
-
1752
- See Also
1753
- --------
1754
- set_printoptions, get_printoptions
1755
-
1756
- Examples
1757
- --------
1758
- >>> from numpy._core.arrayprint import set_string_function
1759
- >>> def pprint(arr):
1760
- ... return 'HA! - What are you going to do now?'
1761
- ...
1762
- >>> set_string_function(pprint)
1763
- >>> a = np.arange(10)
1764
- >>> a
1765
- HA! - What are you going to do now?
1766
- >>> _ = a
1767
- >>> # [0 1 2 3 4 5 6 7 8 9]
1768
-
1769
- We can reset the function to the default:
1770
-
1771
- >>> set_string_function(None)
1772
- >>> a
1773
- array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
1774
-
1775
- `repr` affects either pretty printing or normal string representation.
1776
- Note that ``__repr__`` is still affected by setting ``__str__``
1777
- because the width of each array element in the returned string becomes
1778
- equal to the length of the result of ``__str__()``.
1779
-
1780
- >>> x = np.arange(4)
1781
- >>> set_string_function(lambda x:'random', repr=False)
1782
- >>> x.__str__()
1783
- 'random'
1784
- >>> x.__repr__()
1785
- 'array([0, 1, 2, 3])'
1786
-
1787
- """
1788
-
1789
- # Deprecated in NumPy 2.0, 2023-07-11
1790
- warnings .warn (
1791
- "`set_string_function` is deprecated. Use `np.set_printoptions` "
1792
- "with a formatter for custom printing NumPy objects. "
1793
- "(deprecated in NumPy 2.0)" ,
1794
- DeprecationWarning ,
1795
- stacklevel = 2
1796
- )
1797
-
1798
- if f is None :
1799
- if repr :
1800
- return multiarray .set_string_function (_default_array_repr , 1 )
1801
- else :
1802
- return multiarray .set_string_function (_default_array_str , 0 )
1803
- else :
1804
- return multiarray .set_string_function (f , repr )
0 commit comments