Repository: mars-project/mars

Issue:
[BUG] mars.tensor.int is not compatible with numpy since v1.24
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

**Describe the bug**
Since numpy v1.24, numpy.int, numpy.float, numpy.object, numpy.bool is no longer able to be imported, while cases are that mt.int is used. Deprecate warnings removed by PR #2788 finally come into reality.

**To Reproduce**
To help us reproducing this bug, please provide information below:
1. Your Python version: v3.8.13
2. The version of Mars you use: master
3. Versions of crucial packages, numpy v1.24.1
4. Full stack of the error.
AttributeError: module 'mars.tensor' has no attribute 'int'
5. Minimized code to reproduce the error.
> import mars.tensor as mt
> mt.int

**Expected behavior**
AttributeError: module 'mars.tensor' has no attribute 'int'

**Additional context**
- [Using the aliases of builtin types like np.int is deprecated](https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations)
- [NumPy 1.24 Release Notes](https://numpy.org/devdocs/release/1.24.0-notes.html)
- [DEP: Next step in scalar type alias deprecations/futurewarnings by seberg · Pull Request #22607 · numpy/numpy](https://github.com/numpy/numpy/pull/22607)
- [NumPy 1.22 dropped Python 3.7](https://numpy.org/devdocs/release/1.22.0-notes.html)


Discussion:

Resolving patch:
diff --git a/mars/tensor/__init__.py b/mars/tensor/__init__.py
--- a/mars/tensor/__init__.py
+++ b/mars/tensor/__init__.py
@@ -334,14 +334,14 @@
     character,
     generic,
     flexible,
-    int_,
-    bool_,
-    float_,
+    int_ as int,
+    bool_ as bool,
+    float_ as float,
     cfloat,
     bytes_,
     unicode_,
     void,
-    object_,
+    object_ as object,
     intc,
     intp,
     int8,
@@ -371,20 +371,6 @@
 from .fetch import TensorFetch, TensorFetchShuffle
 from . import ufunc
 
-try:
-    import warnings
-
-    # suppress numpy warnings on types
-    with warnings.catch_warnings():
-        warnings.simplefilter("ignore", DeprecationWarning)
-        warnings.simplefilter("ignore", FutureWarning)
-        # noinspection PyUnresolvedReferences
-        from numpy import object, int, bool, float
-except ImportError:  # pragma: no cover
-    pass
-finally:
-    del warnings
-
 del (
     TensorFuseChunk,
     TensorCpFuseChunk,


Test patch:
diff --git a/mars/learn/datasets/tests/test_samples_generator.py b/mars/learn/datasets/tests/test_samples_generator.py
--- a/mars/learn/datasets/tests/test_samples_generator.py
+++ b/mars/learn/datasets/tests/test_samples_generator.py
@@ -110,7 +110,7 @@ def test_make_classification_informative_features(setup):
         (2, [1 / 2] * 2, 2),
         (2, [3 / 4, 1 / 4], 2),
         (10, [1 / 3] * 3, 10),
-        (np.int(64), [1], 1),
+        (np.int_(64), [1], 1),
     ]:
         n_classes = len(weights)
         n_clusters = n_classes * n_clusters_per_class
diff --git a/mars/learn/utils/tests/test_multiclass.py b/mars/learn/utils/tests/test_multiclass.py
--- a/mars/learn/utils/tests/test_multiclass.py
+++ b/mars/learn/utils/tests/test_multiclass.py
@@ -117,7 +117,7 @@
         [()],
         # sequence of sequences that weren't supported even before deprecation
         np.array([np.array([]), np.array([1, 2, 3])], dtype=object),
-        [np.array([]), np.array([1, 2, 3])],
+        # [np.array([]), np.array([1, 2, 3])], # deprecated in numpy v1.24
         [{1, 2, 3}, {1, 2}],
         [frozenset([1, 2, 3]), frozenset([1, 2])],
         # and also confusable as sequences of sequences
@@ -222,7 +222,7 @@ def test_is_multilabel(setup):
     raws = [
         [[1, 2]],
         [0, 1, 0, 1],
-        [[1], [0, 2], []],
+        # [[1], [0, 2], []], # deprecated in numpy v1.24
         np.array([[1, 0], [0, 0]]),
         np.array([[1], [0], [0]]),
         np.array([[1, 0, 0]]),
diff --git a/mars/tests/test_session.py b/mars/tests/test_session.py
--- a/mars/tests/test_session.py
+++ b/mars/tests/test_session.py
@@ -188,7 +188,7 @@ def test_array_protocol(setup):
 
     arr2 = mt.ones((10, 20))
 
-    result = np.asarray(arr2, mt.bool_)
+    result = np.asarray(arr2, mt.bool)
     np.testing.assert_array_equal(result, np.ones((10, 20), dtype=np.bool_))
 
     arr3 = mt.ones((10, 20)).sum()