Repository: mars-project/mars

Issue:
[BUG] TypeError: copy() got an unexpected keyword argument 'order'
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

**Describe the bug**
When I run the example in "where.py", the code is as follows:

```
>>> import mars.tensor as mt
>>> from mars.session import new_session
>>> sess = new_session().as_default()
>>> x = mt.arange(9.).reshape(3, 3)
>>> sess.run(mt.where( x > 5 ))
```

The annotation of "many.py" says that the result should be "(array([0, 1]), array([1, 0]))", but now it throws error.

**To Reproduce**
To help us reproducing this bug, please provide information below:
1. Your Python version: Python3.7
2. The version of Mars you use: 0.3.0
3. Versions of crucial packages, such as numpy, scipy and protobuf: numpy 1.18.1, scipy 1.3.2
4. Full stack of the error.

```
runfile('C:/Users/Lenovo/Desktop/test/mars/test.py', wdir='C:/Users/Lenovo/Desktop/test/mars')
Traceback (most recent call last):

  File "C:\Users\Lenovo\Desktop\test\mars\test.py", line 25, in <module>
    sess.run(mt.where( x > 5 ))

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\session.py", line 183, in run
    result = self._sess.run(*tileables, **kw)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\session.py", line 90, in run
    res = self._executor.execute_tileables(tileables, **kw)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 392, in _wrapped
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 480, in inner
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\executor.py", line 745, in execute_tileables
    tileables, tileable_graph=tileable_graph)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 392, in _wrapped
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 480, in inner
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 342, in build
    tileables, tileable_graph=tileable_graph)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 392, in _wrapped
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 480, in inner
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 256, in build
    self._on_tile_failure(tileable_data.op, exc_info)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 294, in inner
    six.reraise(*exc_info)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\lib\six.py", line 703, in reraise
    raise value

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 236, in build
    tiled = self._tile(tileable_data, tileable_graph)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 330, in _tile
    return super(IterativeChunkGraphBuilder, self)._tile(tileable_data, tileable_graph)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 194, in _tile
    tds[0]._inplace_tile()

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\core.py", line 162, in _inplace_tile
    return handler.inplace_tile(self)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 128, in inplace_tile
    dispatched = self.dispatch(to_tile.op)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\utils.py", line 392, in _wrapped
    return func(*args, **kwargs)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tiles.py", line 116, in dispatch
    return op_cls.tile(op)

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tensor\indexing\nonzero.py", line 52, in tile
    flattened = in_tensor.astype(bool).flatten()

  File "D:\ProgramData\Anaconda3\lib\site-packages\mars\tensor\base\astype.py", line 146, in _astype
    return tensor if not copy else tensor.copy(order=order)

TypeError: copy() got an unexpected keyword argument 'order'

```

5. Minimized code to reproduce the error.

```
>>> import mars.tensor as mt
>>> from mars.session import new_session
>>> sess = new_session().as_default()
>>> x = mt.arange(9.).reshape(3, 3)
>>> sess.run(mt.where( x > 5 ))
```

**Expected behavior**
(array([2, 2, 2]), array([0, 1, 2]))
That is what the annotation of "many.py" says.

**Additional context**
Please help me, thank you very much.



Discussion:
Thank you for your report, I can reproduce the error.

We will fix the bug very soon.

Resolving patch:
diff --git a/mars/tensor/indexing/nonzero.py b/mars/tensor/indexing/nonzero.py
--- a/mars/tensor/indexing/nonzero.py
+++ b/mars/tensor/indexing/nonzero.py
@@ -47,7 +47,7 @@ def __call__(self, a):
     def tile(cls, op):
         from ..datasource import arange
 
-        in_tensor = op.input
+        in_tensor = astensor(op.input)
 
         flattened = in_tensor.astype(bool).flatten()
         recursive_tile(flattened)


Test patch:
diff --git a/mars/tensor/indexing/tests/test_indexing_execute.py b/mars/tensor/indexing/tests/test_indexing_execute.py
--- a/mars/tensor/indexing/tests/test_indexing_execute.py
+++ b/mars/tensor/indexing/tests/test_indexing_execute.py
@@ -526,6 +526,13 @@ def testNonzeroExecution(self):
 
         np.testing.assert_array_equal(res, expected)
 
+        t = hstack((x > 1).nonzero())
+
+        res = self.executor.execute_tensor(t, concat=True)[0]
+        expected = np.hstack(np.nonzero(data > 1))
+
+        np.testing.assert_array_equal(res, expected)
+
     def testFlatnonzeroExecution(self):
         x = arange(-2, 3, chunk_size=2)