internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: praw-dev/praw

Issue:
documentation incorrect: muted() → praw.models.reddit.subreddit.SubredditRelationship
### Describe the Bug

Errors when example code is executed. 

Docs here: https://praw.readthedocs.io/en/stable/code_overview/other/subredditrelationship.html#praw.models.reddit.subreddit.SubredditRelationship

### Desired Result

Change the docs?  

### Relevant Logs

```shell
c:\python39\lib\site-packages\praw\models\reddit\base.py in __getattr__(self, attribute)
     33         if not attribute.startswith("_") and not self._fetched:
     34             self._fetch()
---> 35             return getattr(self, attribute)
     36         raise AttributeError(
     37             f"{self.__class__.__name__!r} object has no attribute {attribute!r}"

c:\python39\lib\site-packages\praw\models\reddit\base.py in __getattr__(self, attribute)
     34             self._fetch()
     35             return getattr(self, attribute)
---> 36         raise AttributeError(
     37             f"{self.__class__.__name__!r} object has no attribute {attribute!r}"
     38         )

AttributeError: 'Redditor' object has no attribute 'note'
```


### Code to reproduce the bug

```python
for mute in reddit.subreddit("test").muted():
    print(f"{mute}: {mute.note}")
```


### My code example does not include the `Reddit()` initialization to prevent credential leakage.

Yes

### This code has previously worked as intended.

Yes

### Operating System/Environment

windoze

### Python Version

python 3.9.1

### PRAW Version

7.4.0

### Prawcore Version

2.3.0

### Anything else?

Docs here: https://praw.readthedocs.io/en/stable/code_overview/other/subredditrelationship.html#praw.models.reddit.subreddit.SubredditRelationship


Discussion:
Muted relationships do not have notes (technically they do but they are only retuned in html response on the website). As far as I know only banned and wikibanned have has that attribute (which is why code shows banned).

For the doc example, it is iterating through banned and those do have note attributes.
Ack, sorry, wrong link.  

https://praw.readthedocs.io/en/stable/code_overview/models/subreddit.html#praw.models.Subreddit.muted

That one shows the code above.
@LilSpazJoekp dunno if you see updates after you close an issue
Ah yep that should be fixed. Do you want to open an PR to fix this?

Resolving patch:
diff --git a/praw/models/reddit/subreddit.py b/praw/models/reddit/subreddit.py
--- a/praw/models/reddit/subreddit.py
+++ b/praw/models/reddit/subreddit.py
@@ -653,7 +653,7 @@ def muted(self) -> "praw.models.reddit.subreddit.SubredditRelationship":
         .. code-block:: python
 
             for mute in reddit.subreddit("test").muted():
-                print(f"{mute}: {mute.note}")
+                print(f"{mute}: {mute.date}")
 
         """
         return SubredditRelationship(self, "muted")


Test patch:
Repository: mars-project/mars

Issue:
[BUG][DISTRIBUTED] client may hang if something wrong happens in the scheduler
**Describe the bug**

If some errors occur in the distributed, the client may hang, #8 and #17 are examples.

**To Reproduce**

As examples in #8 and #17.

**Expected behavior**

Either we deliver the error to the client, or we hide the real error and deliver an InternalServerError to the client.

**Additional context**

We should separate the system error with the user caused error. We should add some tests.



Discussion:
Up to now all the cases are in the same scenario where the graph preparation fails but the graph state is not properly switched to ``GraphState.FAILED``. These cases should be fixed first.

Resolving patch:
diff --git a/mars/scheduler/graph.py b/mars/scheduler/graph.py
--- a/mars/scheduler/graph.py
+++ b/mars/scheduler/graph.py
@@ -182,6 +182,8 @@ def stop_graph(self):
         self.state = GraphState.CANCELLING
 
         for chunk in self.get_chunk_graph():
+            if chunk.op.key not in self._operand_infos:
+                continue
             if self._operand_infos[chunk.op.key]['state'] in \
                     (OperandState.READY, OperandState.RUNNING, OperandState.FINISHED):
                 # we only need to stop on ready, running and finished operands
diff --git a/mars/web/api.py b/mars/web/api.py
--- a/mars/web/api.py
+++ b/mars/web/api.py
@@ -106,6 +106,8 @@ def get(self, session_id, graph_key):
             self.write(json.dumps(dict(state='failed')))
         elif state == GraphState.CANCELLED:
             self.write(json.dumps(dict(state='cancelled')))
+        elif state == GraphState.CANCELLING:
+            self.write(json.dumps(dict(state='cancelling')))
         elif state == GraphState.PREPARING:
             self.write(json.dumps(dict(state='preparing')))
 
diff --git a/mars/web/session.py b/mars/web/session.py
--- a/mars/web/session.py
+++ b/mars/web/session.py
@@ -95,7 +95,7 @@ def run(self, tensors, compose=True, wait=True, timeout=-1):
                         continue
                     elif resp_json['state'] == 'success':
                         break
-                    elif resp_json['state'] == 'cancelled':
+                    elif resp_json['state'] == ('cancelled', 'cancelling'):
                         raise ExecutionInterrupted
                     elif resp_json['state'] == 'failed':
                         # TODO add traceback


Test patch:
Repository: mars-project/mars

Issue:
[BUG][client] web session has a different signature with the local session
**Describe the bug**

Web has it's own session, but it's `run` method has a different signature with the local session, which lead to a bug that when user submits more than one tensor, only the first tensor would be executed.

**To Reproduce**

```python
In [14]: from mars.session import new_session                                   

In [15]: sess = new_session('http://0.0.0.0:49911')                             

In [16]: a = mt.ones((2, 2))                                                    

In [17]: sess.run(a, a+1)                                                       
Out[17]: 
[array([[1., 1.],
        [1., 1.]])]
```





Discussion:
I doubt that #8 has some connection with this bug.

Resolving patch:
diff --git a/mars/web/session.py b/mars/web/session.py
--- a/mars/web/session.py
+++ b/mars/web/session.py
@@ -24,6 +24,7 @@
 from ..compat import six, TimeoutError
 from ..serialize import dataserializer
 from ..errors import ExecutionInterrupted
+from ..graph import DirectedGraph
 
 logger = logging.getLogger(__name__)
 
@@ -51,12 +52,14 @@ def _main(self):
         content = json.loads(resp.text)
         self._session_id = content['session_id']
 
-    def run(self, tensors, compose=True, wait=True, timeout=-1):
-        from ..graph import DirectedGraph
-        graph = DirectedGraph()
+    def run(self, *tensors, **kw):
+        timeout = kw.pop('timeout', -1)
+        compose = kw.pop('compose', True)
+        wait = kw.pop('wait', True)
+        if kw:
+            raise TypeError('run got unexpected key arguments {0}'.format(', '.join(kw.keys())))
 
-        if not isinstance(tensors, (list, tuple, set)):
-            tensors = [tensors]
+        graph = DirectedGraph()
         for t in tensors:
             graph = t.build_graph(graph=graph, tiled=False, compose=compose)
         targets = [t.key for t in tensors]


Test patch:
diff --git a/mars/web/tests/test_api.py b/mars/web/tests/test_api.py
--- a/mars/web/tests/test_api.py
+++ b/mars/web/tests/test_api.py
@@ -167,6 +167,11 @@ def testApi(self):
             value = sess.run(c, timeout=120)
             assert_array_equal(value, va.dot(vb))
 
+            # test test multiple outputs
+            a = mt.random.rand(10, 10)
+            U, s, V, raw = sess.run(list(mt.linalg.svd(a)) + [a])
+            np.testing.assert_allclose(U.dot(np.diag(s).dot(V)), raw)
+
             # check web UI requests
             res = requests.get(service_ep)
             self.assertEqual(res.status_code, 200)
Repository: mars-project/mars

Issue:
make the fuse logic separated out of graph
For now, the fuse logic is adhere to the graph.pyx, we should separate the logic out of graph, and make it standalone, so we can do some unit test on the fuse.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -81,6 +81,7 @@ def execfile(fname, globs, locs=None):
 extension_kw['include_dirs'] = [np.get_include()]
 extensions = [
     Extension('mars.graph', ['mars/graph.pyx'], **extension_kw),
+    Extension('mars.fuse', ['mars/fuse.pyx'], **extension_kw),
     Extension('mars.utils_c', ['mars/utils_c.pyx'], **extension_kw),
     Extension('mars.lib.gipc', ['mars/lib/gipc.pyx'], **extension_kw),
     Extension('mars.actors.core', ['mars/actors/core.pyx'], **extension_kw),


Test patch:
Repository: mars-project/mars

Issue:
[BUG][TENSOR] Cannot run a tensor tuple by web session
**Describe the bug**
When created a web session to submit the tensors to cluster, it raised `TypeError: run got unexpected key arguments n_parallel` which may be caused by class `ExecutableTuple`.

**To Reproduce**
I start a local  cluster with web, and run SVD of a random matrix.
```
n [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.linalg.svd(t).execute()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-7615968c966e> in <module>()
----> 1 mt.linalg.svd(t).execute()

~/Documents/mars_dev/mars/mars/tensor/core.py in execute(self, session, n_parallel)
    466         if session is None:
    467             session = Session.default_or_local()
--> 468         return session.run(*self, n_parallel=n_parallel)
    469 
    470 

~/Documents/mars_dev/mars/mars/session.py in run(self, *tensors, **kw)
     81 
     82         tensors = tuple(mt.tensor(t) for t in tensors)
---> 83         result = self._sess.run(*tensors, **kw)
     84         self._executed_keys.update(t.key for t in tensors)
     85         for t in tensors:

~/Documents/mars_dev/mars/mars/deploy/local/session.py in run(self, *tensors, **kw)
     47         timeout = kw.pop('timeout', -1)
     48         if kw:
---> 49             raise TypeError('run got unexpected key arguments {0}'.format(', '.join(kw.keys())))
     50 
     51         graph = DirectedGraph()

TypeError: run got unexpected key arguments n_parallel
```



Discussion:

Resolving patch:
diff --git a/mars/tensor/core.py b/mars/tensor/core.py
--- a/mars/tensor/core.py
+++ b/mars/tensor/core.py
@@ -460,12 +460,12 @@ def visualize(self, graph_attrs=None, node_attrs=None, **kw):
 
 
 class ExecutableTuple(tuple):
-    def execute(self, session=None, n_parallel=None):
+    def execute(self, session=None, **kw):
         from ..session import Session
 
         if session is None:
             session = Session.default_or_local()
-        return session.run(*self, n_parallel=n_parallel)
+        return session.run(*self, **kw)
 
 
 class ChunksIndexer(object):


Test patch:
diff --git a/mars/web/tests/test_api.py b/mars/web/tests/test_api.py
--- a/mars/web/tests/test_api.py
+++ b/mars/web/tests/test_api.py
@@ -185,6 +185,12 @@ def testApi(self):
             res = requests.get(service_ep + '/worker')
             self.assertEqual(res.status_code, 200)
 
+        # test default session run with multiple inputs
+        with new_session(service_ep).as_default() as sess:
+            a = mt.ones((20, 10), chunks=10)
+            u, s, v = (mt.linalg.svd(a)).execute()
+            np.testing.assert_allclose(u.dot(np.diag(s).dot(v)), np.ones((20, 10)))
+
 
 class MockResponse:
     def __init__(self, status_code, json_text=None, data=None):
Repository: mars-project/mars

Issue:
By default use core number as n_parallel for threaded scheduling
Use core number as `n_parallel` for threaded scheduling, currently 1 thread by default.


Discussion:

Resolving patch:
diff --git a/mars/session.py b/mars/session.py
--- a/mars/session.py
+++ b/mars/session.py
@@ -16,6 +16,11 @@
 
 import numpy as np
 
+try:
+    from .resource import cpu_count
+except ImportError:
+    from multiprocessing import cpu_count
+
 
 class LocalSession(object):
     def __init__(self):
@@ -37,6 +42,8 @@ def endpoint(self, endpoint):
     def run(self, *tensors, **kw):
         if self._executor is None:
             raise RuntimeError('Session has closed')
+        if 'n_parallel' not in kw:
+            kw['n_parallel'] = cpu_count()
         return self._executor.execute_tensors(tensors, **kw)
 
     def decref(self, *keys):


Test patch:
Repository: mars-project/mars

Issue:
Implement __array__ protocol for Tensor
**Is your feature request related to a problem? Please describe.**

By now, Mars tensor does not implement `__array__` protocol, so if `numpy.asarray` is called, will not get the right result.

**Describe the solution you'd like**

Call `execute` inside `__array__` function.

**Additional context**

Consider the [`__array_function__` protocol ](https://www.numpy.org/neps/nep-0018-array-function-protocol.html) also.


Discussion:

Resolving patch:
diff --git a/mars/tensor/core.py b/mars/tensor/core.py
--- a/mars/tensor/core.py
+++ b/mars/tensor/core.py
@@ -546,6 +546,9 @@ def imag(self, new_imag):
 
         self._data = set_imag(self._data, new_imag).data
 
+    def __array__(self, dtype=None):
+        return np.asarray(self.execute(), dtype=dtype)
+
 
 class SparseTensor(Tensor):
     __slots__ = ()


Test patch:
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
@@ -162,3 +162,24 @@ def testBoolIndexing(self):
         arr3 = arr2.reshape((5, 5))
         expected = np.ones((5, 5))
         np.testing.assert_array_equal(arr3.execute(), expected)
+
+    def testArrayProtocol(self):
+        arr = mt.ones((10, 20))
+
+        result = np.asarray(arr)
+        np.testing.assert_array_equal(result, np.ones((10, 20)))
+
+        arr2 = mt.ones((10, 20))
+
+        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()
+
+        result = np.asarray(arr3)
+        np.testing.assert_array_equal(result, np.asarray(200))
+
+        arr4 = mt.ones((10, 20)).sum()
+
+        result = np.asarray(arr4, dtype=np.float_)
+        np.testing.assert_array_equal(result, np.asarray(200, dtype=np.float_))
Repository: mars-project/mars

Issue:
[BUG] mars-* scripts not marked as executable
**Describe the bug**
Scripts in scripts/ dir not marked as executable when packed into wheels, thus when installed in venvs, they cannot be installed.

**To Reproduce**
To help us reproducing this bug, please provide information below:
1. Your Python version
  Python 3.7.1 installed with pyenv
2. The version of Mars you use
  0.1.0b1
3. Versions of crucial packages, such as numpy, scipy and protobuf
  not relevant
4. Full stack of the error.
  NA
5. Minimized code to reproduce the error.
  mars-scheduler ......



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -111,7 +111,11 @@ def execfile(fname, globs, locs=None):
     ],
     packages=find_packages(exclude=('*.tests.*', '*.tests')),
     include_package_data=True,
-    scripts=['scripts/mars-scheduler', 'scripts/mars-worker', 'scripts/mars-web'],
+    entry_points={'console_scripts': [
+        'mars-scheduler = mars.scheduler.__main__:main',
+        'mars-worker = mars.worker.__main__:main',
+        'mars-web = mars.web.__main__:main',
+    ]},
     install_requires=requirements,
     cmdclass={'build_ext': build_ext},
     ext_modules=cythonize(extensions, **cythonize_kw),


Test patch:
Repository: mars-project/mars

Issue:
[BUG] Parse cache_limit before it being used
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

**Describe the bug**
   https://github.com/mars-project/mars/blob/ebd2b0234b8580d562415380f5b8204b16b34c1f/mars/worker/service.py#L84-L86
   https://github.com/mars-project/mars/blob/ebd2b0234b8580d562415380f5b8204b16b34c1f/mars/worker/__main__.py#L75
   When `cache_mem` as a `str` is passed by users, `options.worker.cache_memory_limit` is assigned to `cache_mem` in `create_pool`. It is not parsed before being used here. It can still be a `str` on this line. And `str - int` throws an exception.

**To Reproduce**
   Start the worker with '--cache_mem XXXm' specified.

**Expected behavior**
   It should be an int?

**Additional context**
   It seems to #141 deliberately delete the parsing line?



Discussion:
Thank you very much. Now we are refactoring service and application classes, trying to simplify initialization as well as facilitate testing. These problems will be resolved and cases will be added.
@wjsi I see, thx!
Reopen since it has not been fixed.

Resolving patch:
diff --git a/mars/worker/__main__.py b/mars/worker/__main__.py
--- a/mars/worker/__main__.py
+++ b/mars/worker/__main__.py
@@ -72,7 +72,9 @@ def create_pool(self, *args, **kwargs):
         options.worker.physical_memory_limit_soft = self._calc_size_limit(
             options.worker.physical_memory_limit_soft, self._total_mem
         )
-        options.worker.cache_memory_limit = self.args.cache_mem
+        options.worker.cache_memory_limit = self._calc_size_limit(
+            self.args.cache_mem, self._total_mem
+        )
         options.worker.disk_limit = self.args.disk
         if self.args.spill_dir:
             from .spill import parse_spill_dirs


Test patch:
Repository: mars-project/mars

Issue:
Add guide for develop installations
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

We need to add guidances for developers to install from github and prepare for development, both in README and docs.


Discussion:

Resolving patch:
diff --git a/mars/base_app.py b/mars/base_app.py
--- a/mars/base_app.py
+++ b/mars/base_app.py
@@ -73,7 +73,8 @@ def __call__(self, argv=None):
     def _main(self, argv=None):
         parser = argparse.ArgumentParser(description=self.service_description)
         parser.add_argument('-a', '--advertise', help='advertise ip')
-        parser.add_argument('-k', '--kv-store', help='address of kv store service, for instance, etcd')
+        parser.add_argument('-k', '--kv-store', help='address of kv store service, '
+                                                     'for instance, etcd://localhost:4001')
         parser.add_argument('-e', '--endpoint', help='endpoint of the service')
         parser.add_argument('-s', '--schedulers', help='endpoint of scheduler, when single scheduler '
                                                        'and etcd is not available')
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -37,11 +37,13 @@ def execfile(fname, globs, locs=None):
 with open(os.path.join(repo_root, 'requirements.txt'), 'r') as f:
     requirements.extend(f.read().splitlines())
 
-
 extra_requirements = []
 with open(os.path.join(repo_root, 'requirements-extra.txt'), 'r') as f:
     extra_requirements.extend(f.read().splitlines())
 
+dev_requirements = []
+with open(os.path.join(repo_root, 'requirements-dev.txt'), 'r') as f:
+    dev_requirements.extend(f.read().splitlines())
 
 long_description = None
 if os.path.exists(os.path.join(repo_root, 'README.rst')):
@@ -119,6 +121,9 @@ def execfile(fname, globs, locs=None):
     install_requires=requirements,
     cmdclass={'build_ext': build_ext},
     ext_modules=cythonize(extensions, **cythonize_kw),
-    extras_require={'distributed': extra_requirements}
+    extras_require={
+        'distributed': extra_requirements,
+        'dev': extra_requirements + dev_requirements,
+    }
 )
 setup(**setup_options)


Test patch:
Repository: mars-project/mars

Issue:
Add __mars_tokenize__ protocol for objects that can be tokenized
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

**Is your feature request related to a problem? Please describe.**

Tokenize is used to generate an unique key that represents an object, currently if some property of an object to tokenize cannot be recognized, we would add a tokenize handler for this property manually in the `utils_c.pyx`, thus I suggest to add a `__mars_tokenize__` protocol which generates an object can definitely be tokenized.

What's more, I am going to rename the `utils_c.pyx` to `_utils.pyx`.


Discussion:

Resolving patch:
diff --git a/mars/dataframe/core.py b/mars/dataframe/core.py
--- a/mars/dataframe/core.py
+++ b/mars/dataframe/core.py
@@ -108,6 +108,11 @@ class MultiIndex(Serializable):
                               int64_index=Int64Field, uint64_index=UInt64Index,
                               float64_index=Float64Index, multi_index=MultiIndex)
 
+    def __mars_tokenize__(self):
+        # return object for tokenize
+        v = self._index_value
+        return [type(v).__name__] + [getattr(v, f, None) for f in v.__slots__]
+
 
 class IndexChunkData(ChunkData):
     __slots__ = ()
diff --git a/mars/utils.py b/mars/utils.py
--- a/mars/utils.py
+++ b/mars/utils.py
@@ -33,7 +33,7 @@
 import numpy as np
 
 from .compat import irange, functools32, getargspec
-from .utils_c import to_binary, to_str, to_text, tokenize
+from ._utils import to_binary, to_str, to_text, tokenize
 from .config import options
 
 logger = logging.getLogger(__name__)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -74,7 +74,7 @@ def execfile(fname, globs, locs=None):
 extensions = [
     Extension('mars.graph', ['mars/graph.pyx'], **extension_kw),
     Extension('mars.fuse', ['mars/fuse.pyx'], **extension_kw),
-    Extension('mars.utils_c', ['mars/utils_c.pyx'], **extension_kw),
+    Extension('mars._utils', ['mars/_utils.pyx'], **extension_kw),
     Extension('mars.lib.gipc', ['mars/lib/gipc.pyx'], **extension_kw),
     Extension('mars.actors.core', ['mars/actors/core.pyx'], **extension_kw),
     Extension('mars.actors.distributor', ['mars/actors/distributor.pyx'], **extension_kw),


Test patch:
Repository: mars-project/mars

Issue:
[BUG] Chinese document layout has a link error.
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

**Describe the bug**
A clear and concise description of what the bug is.

Chinese document layout has a connection error.
doc link:[https://mars-project.readthedocs.io/zh_CN/latest/tensor/overview.html](https://mars-project.readthedocs.io/zh_CN/latest/tensor/overview.html)


![image](https://user-images.githubusercontent.com/20548053/54252653-9e94d900-4586-11e9-998f-3b677dd2b460.png)




Discussion:

Resolving patch:
diff --git a/docs/source/norm_zh.py b/docs/source/norm_zh.py
--- a/docs/source/norm_zh.py
+++ b/docs/source/norm_zh.py
@@ -130,7 +130,7 @@ def main():
 
             # only modify recent-changed files
             modify_time = datetime.datetime.fromtimestamp(os.path.getmtime(path))
-            if (datetime.datetime.now() - modify_time).total_seconds() > 1800:
+            if (datetime.datetime.now() - modify_time).total_seconds() > 120:
                 continue
 
             with open(path, 'rb') as inpf:


Test patch: