(self)
| 8765 | self_containing[0] = None # resolve circular reference |
| 8766 | |
| 8767 | def test_to_int_scalar(self): |
| 8768 | # gh-9972 means that these aren't always the same |
| 8769 | int_funcs = (int, lambda x: x.__int__()) |
| 8770 | for int_func in int_funcs: |
| 8771 | assert_equal(int_func(np.array(0)), 0) |
| 8772 | with assert_warns(DeprecationWarning): |
| 8773 | assert_equal(int_func(np.array([1])), 1) |
| 8774 | with assert_warns(DeprecationWarning): |
| 8775 | assert_equal(int_func(np.array([[42]])), 42) |
| 8776 | assert_raises(TypeError, int_func, np.array([1, 2])) |
| 8777 | |
| 8778 | # gh-9972 |
| 8779 | assert_equal(4, int_func(np.array('4'))) |
| 8780 | assert_equal(5, int_func(np.bytes_(b'5'))) |
| 8781 | assert_equal(6, int_func(np.str_('6'))) |
| 8782 | |
| 8783 | # The delegation of int() to __trunc__ was deprecated in |
| 8784 | # Python 3.11. |
| 8785 | if sys.version_info < (3, 11): |
| 8786 | class HasTrunc: |
| 8787 | def __trunc__(self): |
| 8788 | return 3 |
| 8789 | assert_equal(3, int_func(np.array(HasTrunc()))) |
| 8790 | with assert_warns(DeprecationWarning): |
| 8791 | assert_equal(3, int_func(np.array([HasTrunc()]))) |
| 8792 | else: |
| 8793 | pass |
| 8794 | |
| 8795 | class NotConvertible: |
| 8796 | def __int__(self): |
| 8797 | raise NotImplementedError |
| 8798 | assert_raises(NotImplementedError, |
| 8799 | int_func, np.array(NotConvertible())) |
| 8800 | with assert_warns(DeprecationWarning): |
| 8801 | assert_raises(NotImplementedError, |
| 8802 | int_func, np.array([NotConvertible()])) |
| 8803 | |
| 8804 | |
| 8805 | class TestWhere: |
nothing calls this directly
no test coverage detected