gurudesh/pytracebugs huggingface dataset:
# Buggy code
def __init__(self):
    threading.Thread.__init__(self, name="objectProcessor")
    random.seed()
    # It may be the case that the last time Bitmessage was running,
    # the user closed it before it finished processing everything in the
    # objectProcessorQueue. Assuming that Bitmessage wasn't closed
    # forcefully, it should have saved the data in the queue into the
    # objectprocessorqueue table. Let's pull it out.
    queryreturn = sqlQuery("""SELECT objecttype, data FROM objectprocessorqueue""")
    for row in queryreturn:
        objectType, data = row
        queues.objectProcessorQueue.put((objectType, data))
    sqlExecute("""DELETE FROM objectprocessorqueue""")
    logger.debug(
        "Loaded %s objects from disk into the objectProcessorQueue.", len(queryreturn)
    )
    self._ack_obj = bmproto.BMStringParser()
    self.successfullyDecryptMessageTimings = []


# Traceback (AssertionError)
2021-01-03 06:30:31,908 - CRITICAL - Unhandled exception
Traceback (most recent call last):
File "Documents/Software/PyBitmessage/src/bitmessagemain.py", line 491, in <module>
File "Documents/Software/PyBitmessage/src/bitmessagemain.py", line 487, in main
File "Documents/Software/PyBitmessage/src/bitmessagemain.py", line 286, in start
File "/home/*****/Documents/Software/PyBitmessage/src/class_objectProcessor.py", line 54, in __init__
'''SELECT objecttype, data FROM objectprocessorqueue''')
File "/home/*****/Documents/Software/PyBitmessage/src/helper_sql.py", line 44, in sqlQuery
assert sql_available
AssertionError
Number of threads: 1

Operating system is Ubuntu 18.04.5 LTS 32-bit.

# Fixed code
def __init__(self):
    threading.Thread.__init__(self, name="objectProcessor")
    random.seed()
    # It may be the case that the last time Bitmessage was running,
    # the user closed it before it finished processing everything in the
    # objectProcessorQueue. Assuming that Bitmessage wasn't closed
    # forcefully, it should have saved the data in the queue into the
    # objectprocessorqueue table. Let's pull it out.
    sql_ready.wait()
    queryreturn = sqlQuery("""SELECT objecttype, data FROM objectprocessorqueue""")
    for row in queryreturn:
        objectType, data = row
        queues.objectProcessorQueue.put((objectType, data))
    sqlExecute("""DELETE FROM objectprocessorqueue""")
    logger.debug(
        "Loaded %s objects from disk into the objectProcessorQueue.", len(queryreturn)
    )
    self._ack_obj = bmproto.BMStringParser()
    self.successfullyDecryptMessageTimings = []
# Buggy code
def stream_decode_response_unicode(iterator, r):
    """Stream decodes a iterator."""
    encoding = r.encoding

    if encoding is None:
        encoding = r.apparent_encoding

    try:
        decoder = codecs.getincrementaldecoder(encoding)(errors="replace")
    except (LookupError, TypeError):
        # A LookupError is raised if the encoding was not found which could
        # indicate a misspelling or similar mistake.
        #
        # A TypeError can be raised if encoding is None
        raise UnicodeError("Unable to decode contents with encoding %s." % encoding)

    for chunk in iterator:
        rv = decoder.decode(chunk)
        if rv:
            yield rv
    rv = decoder.decode(b"", final=True)
    if rv:
        yield rv


# Traceback (AttributeError)
$ ./bin/python case.py

Traceback (most recent call last):
File "case.py", line 6, in <module>
for line in response.iter_lines(chunk_size=30, decode_unicode=True):
File "/Users/jone/temp/requests-stream/lib/python2.7/site-packages/requests/models.py", line 720, in iter_lines
for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
File "/Users/jone/temp/requests-stream/lib/python2.7/site-packages/requests/utils.py", line 374, in stream_decode_response_unicode
for chunk in iterator:
File "/Users/jone/temp/requests-stream/lib/python2.7/site-packages/requests/models.py", line 676, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/Users/jone/temp/requests-stream/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 353, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File "/Users/jone/temp/requests-stream/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 521, in read_chunked
line = self._fp.fp.readline()
AttributeError: 'NoneType' object has no attribute 'readline'

# Fixed code
def stream_decode_response_unicode(iterator, r):
    """Stream decodes a iterator."""

    if r.encoding is None:
        for item in iterator:
            yield item
        return

    decoder = codecs.getincrementaldecoder(r.encoding)(errors="replace")
    for chunk in iterator:
        rv = decoder.decode(chunk)
        if rv:
            yield rv
    rv = decoder.decode(b"", final=True)
    if rv:
        yield rv
# Buggy code
def _encode_params(data):
    """Encode parameters in a piece of data.

    Will successfully encode parameters when passed as a dict or a list of
    2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
    if parameters are supplied as a dict.
    """

    if isinstance(data, (str, bytes)):
        return data
    elif hasattr(data, "read"):
        return data
    elif hasattr(data, "__iter__"):
        result = []
        for k, vs in to_key_val_list(data):
            if isinstance(vs, basestring) or not hasattr(vs, "__iter__"):
                vs = [vs]
            for v in vs:
                if v is not None:
                    result.append(
                        (
                            k.encode("utf-8") if isinstance(k, str) else k,
                            v.encode("utf-8") if isinstance(v, str) else v,
                        )
                    )
        return urlencode(result, doseq=True)
    else:
        return data


# Traceback (TypeError)
Traceback (most recent call last):
... skip ...
url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))
File "C:\Python35\lib\urllib\parse.py", line 383, in urlunparse
_coerce_args(*components))
File "C:\Python35\lib\urllib\parse.py", line 111, in _coerce_args
raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

# Fixed code
def _encode_params(data):
    """Encode parameters in a piece of data.

    Will successfully encode parameters when passed as a dict or a list of
    2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
    if parameters are supplied as a dict.
    """

    if isinstance(data, (str, bytes)):
        return to_native_string(data)
    elif hasattr(data, "read"):
        return data
    elif hasattr(data, "__iter__"):
        result = []
        for k, vs in to_key_val_list(data):
            if isinstance(vs, basestring) or not hasattr(vs, "__iter__"):
                vs = [vs]
            for v in vs:
                if v is not None:
                    result.append(
                        (
                            k.encode("utf-8") if isinstance(k, str) else k,
                            v.encode("utf-8") if isinstance(v, str) else v,
                        )
                    )
        return urlencode(result, doseq=True)
    else:
        return data
# Buggy code
def stream_decode_response_unicode(iterator, r):
    """Stream decodes a iterator."""

    if r.encoding is None:
        for item in iterator:
            yield item
        return

    decoder = codecs.getincrementaldecoder(r.encoding)(errors="replace")
    for chunk in iterator:
        rv = decoder.decode(chunk)
        if rv:
            yield rv
    rv = decoder.decode("", final=True)
    if rv:
        yield rv


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-86c335a3edfc> in <module>()
----> 1 rv = decoder.decode('', final=True)

/Users/chen/Virtualenvs/python3Env/lib/python3.3/codecs.py in decode(self, input, final)
297     def decode(self, input, final=False):
298         # decode input (taking the buffer into account)
--> 299         data = self.buffer + input
300         (result, consumed) = self._buffer_decode(data, self.errors, final)
301         # keep undecoded input until the next call

TypeError: can't concat bytes to str

# Fixed code
def stream_decode_response_unicode(iterator, r):
    """Stream decodes a iterator."""

    if r.encoding is None:
        for item in iterator:
            yield item
        return

    decoder = codecs.getincrementaldecoder(r.encoding)(errors="replace")
    for chunk in iterator:
        rv = decoder.decode(chunk)
        if rv:
            yield rv
    rv = decoder.decode(b"", final=True)
    if rv:
        yield rv
# Buggy code
def text(self):
    """Content of the response, in unicode.

    if Response.encoding is None and chardet module is available, encoding
    will be guessed.
    """

    # Try charset from content-type
    content = None
    encoding = self.encoding

    # Fallback to auto-detected encoding if chardet is available.
    if self.encoding is None:
        encoding = self._detected_encoding()

    # Decode unicode from given encoding.
    try:
        content = str(self.content, encoding, errors="replace")
    except (UnicodeError, TypeError):
        pass

    return content


# Traceback (LookupError)
url = 'http://dilbert.com'
len(urllib2.urlopen(url).read())
30194
len(requests.get(url).content)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/requests/models.py", line 713, in content
LookupError: unknown encoding: utf-8lias


# Fixed code
def text(self):
    """Content of the response, in unicode.

    if Response.encoding is None and chardet module is available, encoding
    will be guessed.
    """

    # Try charset from content-type
    content = None
    encoding = self.encoding

    # Fallback to auto-detected encoding if chardet is available.
    if self.encoding is None:
        encoding = self._detected_encoding()

    # Decode unicode from given encoding.
    try:
        content = str(self.content, encoding, errors="replace")
    except LookupError:
        # A LookupError is raised if the encoding was not found which could
        # indicate a misspelling or similar mistake.
        #
        # So we try blindly encoding.
        content = str(self.content, errors="replace")
    except (UnicodeError, TypeError):
        pass

    return content
# Buggy code
def free_binding(self, guest_id):
    self.lock.acquire()
    try:
        self.bindings[guest_id][0] -= 1

        # stop listening if no-one connected
        if self.bindings[guest_id][0] == 0:
            self.bindings[guest_id][1].stopListening()
            self.bindings[guest_id][2].stopListening()

    finally:
        self.lock.release()


# Traceback (builtins.OSError)
2020-06-08T14:16:22.505410Z [backend_pool.nat.ServerFactory#info] Starting factory <backend_pool.nat.ServerFactory object at 0x7fc035e2ce80>
2020-06-08T14:16:22.507706Z [backend_pool.nat.ClientFactory#info] Starting factory <backend_pool.nat.ClientFactory object at 0x7fc035e2c3c8>
2020-06-08T14:16:22.508111Z [twisted.internet.tcp.Port#info] EMFILE encountered; releasing reserved file descriptor.
2020-06-08T14:16:22.508193Z [twisted.internet.tcp.Port#info] Re-reserving EMFILE recovery file descriptor.
2020-06-08T14:16:22.508593Z [backend_pool.nat.ClientFactory#info] Stopping factory <backend_pool.nat.ClientFactory object at 0x7fc035e2c3c8>
2020-06-08T14:16:23.235361Z [twisted.internet.tcp.Port#info] EMFILE encountered; releasing reserved file descriptor.
2020-06-08T14:16:23.235508Z [twisted.internet.tcp.Port#info] EMFILE recovery: Closed socket from ('172.16.1.6', 42942)
2020-06-08T14:16:23.235537Z [twisted.internet.tcp.Port#info] Re-reserving EMFILE recovery file descriptor.
2020-06-08T14:16:24.463433Z [-] Unhandled Error
Traceback (most recent call last):
File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/application/app.py", line 399, in startReactor

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/application/app.py", line 312, in runReactorWithLogging

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 1283, in run

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 1292, in mainLoop

--- <exception caught here> ---
File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 913, in runUntilCurrent

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 280, in producer_loop

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 190, in __producer_check_health

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 151, in has_connectivity

File "/srv/cowrie/cowrie-github/src/backend_pool/util.py", line 18, in nmap_port

File "/usr/lib/python3.6/subprocess.py", line 423, in run

File "/usr/lib/python3.6/subprocess.py", line 687, in __init__

File "/usr/lib/python3.6/subprocess.py", line 1197, in _get_handles

builtins.OSError: [Errno 24] Too many open files

# Fixed code
def free_binding(self, guest_id):
    self.lock.acquire()
    try:
        self.bindings[guest_id][0] -= 1

        # stop listening if no one is connected
        if self.bindings[guest_id][0] <= 0:
            self.bindings[guest_id][1].stopListening()
            self.bindings[guest_id][2].stopListening()
            del self.bindings[guest_id]
    finally:
        self.lock.release()
# Buggy code
def startFactory(self):
    # start the pool thread with default configs
    self.pool_service = PoolService()
    self.pool_service.start_pool()


# Traceback (builtins.OSError)
2020-06-08T14:16:22.505410Z [backend_pool.nat.ServerFactory#info] Starting factory <backend_pool.nat.ServerFactory object at 0x7fc035e2ce80>
2020-06-08T14:16:22.507706Z [backend_pool.nat.ClientFactory#info] Starting factory <backend_pool.nat.ClientFactory object at 0x7fc035e2c3c8>
2020-06-08T14:16:22.508111Z [twisted.internet.tcp.Port#info] EMFILE encountered; releasing reserved file descriptor.
2020-06-08T14:16:22.508193Z [twisted.internet.tcp.Port#info] Re-reserving EMFILE recovery file descriptor.
2020-06-08T14:16:22.508593Z [backend_pool.nat.ClientFactory#info] Stopping factory <backend_pool.nat.ClientFactory object at 0x7fc035e2c3c8>
2020-06-08T14:16:23.235361Z [twisted.internet.tcp.Port#info] EMFILE encountered; releasing reserved file descriptor.
2020-06-08T14:16:23.235508Z [twisted.internet.tcp.Port#info] EMFILE recovery: Closed socket from ('172.16.1.6', 42942)
2020-06-08T14:16:23.235537Z [twisted.internet.tcp.Port#info] Re-reserving EMFILE recovery file descriptor.
2020-06-08T14:16:24.463433Z [-] Unhandled Error
Traceback (most recent call last):
File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/application/app.py", line 399, in startReactor

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/application/app.py", line 312, in runReactorWithLogging

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 1283, in run

File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 1292, in mainLoop

--- <exception caught here> ---
File "/srv/cowrie/cowrie-venv/lib/python3.6/site-packages/twisted/internet/base.py", line 913, in runUntilCurrent

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 280, in producer_loop

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 190, in __producer_check_health

File "/srv/cowrie/cowrie-github/src/backend_pool/pool_service.py", line 151, in has_connectivity

File "/srv/cowrie/cowrie-github/src/backend_pool/util.py", line 18, in nmap_port

File "/usr/lib/python3.6/subprocess.py", line 423, in run

File "/usr/lib/python3.6/subprocess.py", line 687, in __init__

File "/usr/lib/python3.6/subprocess.py", line 1197, in _get_handles

builtins.OSError: [Errno 24] Too many open files

# Fixed code
def startFactory(self):
    # start the pool thread with default configs
    self.pool_service = PoolService(self.nat)
    self.pool_service.start_pool()
# Buggy code
def write(self, logentry):
    for i in list(logentry.keys()):
        # Remove twisted 15 legacy keys
        if i.startswith("log_"):
            del logentry[i]

    message = json.dumps(logentry) + "\n"

    try:
        self.sock.sendall(message)
    except socket.error as ex:
        if ex.errno == 32:  # Broken pipe
            self.start()
            self.sock.sendall(message)
        else:
            raise


# Traceback (builtins.TypeError)
2019-03-09T18:58:39.452595Z [twisted.logger._observer#critical] Temporarily disabling observer LegacyLogObserverWrapper(<bound method Output.emit of <cowrie.output.socketlog.Output
object at 0x7f1ac2879c18>>) due to exception: [Failure instance: Traceback: <class 'TypeError'>: a bytes-like object is required, not 'str'
/home/cowrie/cowrie/src/cowrie/ssh/transport.py:62:connectionMade
/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/threadable.py:53:sync
/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/log.py:286:msg
/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_legacy.py:154:publishToNewObserver
--- <exception caught here> ---
/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_observer.py:131:__call__
/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_legacy.py:93:__call__
/home/cowrie/cowrie/src/cowrie/core/output.py:214:emit
/home/cowrie/cowrie/src/cowrie/output/socketlog.py:38:write
]
Traceback (most recent call last):
File "/home/cowrie/cowrie/src/cowrie/ssh/transport.py", line 62, in connectionMade
protocol='ssh'
File "/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/threadable.py", line 53, in sync
return function(self, *args, **kwargs)
File "/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/python/log.py", line 286, in msg
_publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
File "/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
observer(eventDict)
--- <exception caught here> ---
File "/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_observer.py", line 131, in __call__
observer(event)
File "/home/cowrie/cowrie/cowrie-env/lib/python3.6/site-packages/twisted/logger/_legacy.py", line 93, in __call__
self.legacyObserver(event)
File "/home/cowrie/cowrie/src/cowrie/core/output.py", line 214, in emit
self.write(ev)
File "/home/cowrie/cowrie/src/cowrie/output/socketlog.py", line 38, in write
self.sock.sendall(message)
builtins.TypeError: a bytes-like object is required, not 'str'

# Fixed code
def write(self, logentry):
    for i in list(logentry.keys()):
        # Remove twisted 15 legacy keys
        if i.startswith("log_"):
            del logentry[i]

    message = json.dumps(logentry) + "\n"

    try:
        self.sock.sendall(message.encode())
    except socket.error as ex:
        if ex.errno == 32:  # Broken pipe
            self.start()
            self.sock.sendall(message.encode())
        else:
            raise
# Buggy code
def __call__(self, input_tensor, index, columns):
    if isinstance(input_tensor, dict):
        return self._call_input_1d_tileables(input_tensor, index, columns)
    else:
        return self._call_input_tensor(input_tensor, index, columns)


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def __call__(self, input_tensor, index, columns):
    if isinstance(input_tensor, dict):
        return self._call_input_1d_tileables(input_tensor, index, columns)
    elif input_tensor is not None:
        return self._call_input_tensor(input_tensor, index, columns)
    else:
        return self._call_tensor_none(index, columns)
# Buggy code
def tile(cls, op):
    if isinstance(op.input, dict):
        return cls._tile_input_1d_tileables(op)
    else:
        return cls._tile_input_tensor(op)


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def tile(cls, op):
    if isinstance(op.input, dict):
        return cls._tile_input_1d_tileables(op)
    elif op.input is not None:
        return cls._tile_input_tensor(op)
    else:
        return cls._tile_tensor_none(op)
# Buggy code
def dataframe_from_tensor(tensor, index=None, columns=None, gpu=None, sparse=False):
    if tensor.ndim > 2 or tensor.ndim <= 0:
        raise TypeError(f"Not support create DataFrame from {tensor.ndim} dims tensor")
    try:
        col_num = tensor.shape[1]
    except IndexError:
        col_num = 1
    gpu = tensor.op.gpu if gpu is None else gpu
    op = DataFrameFromTensor(
        input_=tensor,
        dtypes=pd.Series([tensor.dtype] * col_num, index=columns),
        gpu=gpu,
        sparse=sparse,
    )
    return op(tensor, index, columns)


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def dataframe_from_tensor(tensor, index=None, columns=None, gpu=None, sparse=False):
    if tensor is not None:
        if tensor.ndim > 2 or tensor.ndim <= 0:
            raise TypeError(
                f"Not support create DataFrame from {tensor.ndim} dims tensor"
            )
        try:
            col_num = tensor.shape[1]
        except IndexError:
            col_num = 1
        gpu = tensor.op.gpu if gpu is None else gpu
        dtypes = pd.Series([tensor.dtype] * col_num, index=columns)
    else:
        gpu = None
        if columns is not None:
            dtypes = pd.Series([], index=columns)
        else:
            dtypes = pd.Series([], index=pd.Index([], dtype=object))
    op = DataFrameFromTensor(input_=tensor, dtypes=dtypes, gpu=gpu, sparse=sparse)
    return op(tensor, index, columns)
# Buggy code
def __init__(self, index=None, dtype=None, gpu=None, sparse=None, **kw):
    super().__init__(
        _index=index,
        _dtype=dtype,
        _gpu=gpu,
        _sparse=sparse,
        _output_types=[OutputType.series],
        **kw,
    )


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def __init__(self, input_=None, index=None, dtype=None, gpu=None, sparse=None, **kw):
    super().__init__(
        _input=input_,
        _index=index,
        _dtype=dtype,
        _gpu=gpu,
        _sparse=sparse,
        _output_types=[OutputType.series],
        **kw,
    )
# Buggy code
def _set_inputs(self, inputs):
    super()._set_inputs(inputs)
    self._input = self._inputs[0]
    if self._index is not None:
        self._index = self._inputs[-1]


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def _set_inputs(self, inputs):
    super()._set_inputs(inputs)
    if self._input is not None:
        self._input = self._inputs[0]
    if self._index is not None:
        self._index = self._inputs[-1]
# Buggy code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    tensor_data = ctx[op.inputs[0].key]
    if op.index is not None:
        index_data = ctx[op.inputs[1].key]
    else:
        index_data = chunk.index_value.to_pandas()
    ctx[chunk.key] = pd.Series(tensor_data, index=index_data, name=chunk.name)


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    if op.input is not None:
        tensor_data = ctx[op.input.key]
    else:
        tensor_data = None
    if op.index is not None:
        index_data = ctx[op.index.key]
    else:
        index_data = chunk.index_value.to_pandas()
    ctx[chunk.key] = pd.Series(
        tensor_data, index=index_data, name=chunk.name, dtype=chunk.dtype
    )
# Buggy code
def series_from_tensor(tensor, index=None, name=None, gpu=None, sparse=False):
    if tensor.ndim > 1 or tensor.ndim <= 0:
        raise TypeError(f"Not support create Series from {tensor.ndim} dims tensor")
    gpu = tensor.op.gpu if gpu is None else gpu
    op = SeriesFromTensor(dtype=tensor.dtype, gpu=gpu, sparse=sparse)
    return op(tensor, index, name)


# Traceback (NotImplementedError)
In [52]: df = md.DataFrame(index=[1, 2, 3])

In [53]: df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-53-f550a59ef82c> in <module>
----> 1 df['a'] = md.Series(['a', 'b', 'c'], index=[2, 3, 4])

~/Workspace/mars/mars/dataframe/indexing/setitem.py in dataframe_setitem(df, col, value)
182 def dataframe_setitem(df, col, value):
183     op = DataFrameSetitem(target=df, indexes=col, value=value)
--> 184     return op(df, value)

~/Workspace/mars/mars/utils.py in _inner(*args, **kwargs)
457         @functools.wraps(func)
458         def _inner(*args, **kwargs):
--> 459             with self:
460                 return func(*args, **kwargs)
461

~/Workspace/mars/mars/dataframe/indexing/setitem.py in __call__(self, target, value)
83
84             if value.index_value.key != target.index_value.key:  # pragma: no cover
---> 85                 raise NotImplementedError('Does not support setting value '
86                                           'with different index for now')
87

NotImplementedError: Does not support setting value with different index for now

# Fixed code
def series_from_tensor(
    tensor, index=None, name=None, dtype=None, gpu=None, sparse=False
):
    if tensor is not None:
        if tensor.ndim > 1 or tensor.ndim <= 0:
            raise TypeError(f"Not support create Series from {tensor.ndim} dims tensor")
        gpu = tensor.op.gpu if gpu is None else gpu
        dtype = dtype or tensor.dtype
    else:
        gpu = None
        dtype = dtype or np.dtype(float)
    op = SeriesFromTensor(input_=tensor, dtype=dtype, gpu=gpu, sparse=sparse)
    return op(tensor, index, name)
# Buggy code
def __mars_tensor__(self, dtype=None, order="K"):
    return self._to_mars_tensor(dtype=dtype, order=order)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-f2912f2e33a0> in <module>
1 from mars.learn.metrics import accuracy_score
----> 2 accuracy_score(y_test,y_pred).execute()

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight, session, run_kwargs)
178     op = AccuracyScore(y_true=y_true, y_pred=y_pred, normalize=normalize,
179                        sample_weight=sample_weight)
--> 180     score = op(y_true, y_pred)
181     return score.execute(session=session, **(run_kwargs or dict()))

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in __call__(self, y_true, y_pred)
76
77     def __call__(self, y_true, y_pred):
---> 78         type_true, y_true, y_pred = _check_targets(y_true, y_pred)
79         self._type_true = type_true
80         inputs = [y_true, y_pred, type_true]

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in _check_targets(y_true, y_pred)
193     """
194     op = CheckTargets(y_true=y_true, y_pred=y_pred)
--> 195     return op(y_true, y_pred)

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in __call__(self, y_true, y_pred)
82         if isinstance(y_pred, (Base, Entity)):
83             inputs.append(y_pred)
---> 84         self._type_true = type_of_target(y_true)
85         self._type_pred = type_of_target(y_pred)
86         inputs.extend([self._type_true, self._type_pred])

/home/tops/lib/python3.6/site-packages/mars/learn/utils/multiclass.py in type_of_target(y)
403
404     if not valid:
--> 405         raise ValueError(f'Expected array-like (array or non-string sequence), got {y}')
406
407     sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])

ValueError: Expected array-like (array or non-string sequence), got 159615    0
134010    0
199100    0
137756    0
200050    0
..
219880    0
82326     0
184439    0
198518    0
109959    0
Name: label_bigint, Length: 1146788, dtype: int64

# Fixed code
def __mars_tensor__(self, dtype=None, order="K"):
    return self._data.__mars_tensor__(dtype=dtype, order=order)
# Buggy code
def __mars_tensor__(self, dtype=None, order="K"):
    tensor = self._data.to_tensor()
    dtype = dtype if dtype is not None else tensor.dtype
    return tensor.astype(dtype=dtype, order=order, copy=False)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-f2912f2e33a0> in <module>
1 from mars.learn.metrics import accuracy_score
----> 2 accuracy_score(y_test,y_pred).execute()

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight, session, run_kwargs)
178     op = AccuracyScore(y_true=y_true, y_pred=y_pred, normalize=normalize,
179                        sample_weight=sample_weight)
--> 180     score = op(y_true, y_pred)
181     return score.execute(session=session, **(run_kwargs or dict()))

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in __call__(self, y_true, y_pred)
76
77     def __call__(self, y_true, y_pred):
---> 78         type_true, y_true, y_pred = _check_targets(y_true, y_pred)
79         self._type_true = type_true
80         inputs = [y_true, y_pred, type_true]

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in _check_targets(y_true, y_pred)
193     """
194     op = CheckTargets(y_true=y_true, y_pred=y_pred)
--> 195     return op(y_true, y_pred)

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in __call__(self, y_true, y_pred)
82         if isinstance(y_pred, (Base, Entity)):
83             inputs.append(y_pred)
---> 84         self._type_true = type_of_target(y_true)
85         self._type_pred = type_of_target(y_pred)
86         inputs.extend([self._type_true, self._type_pred])

/home/tops/lib/python3.6/site-packages/mars/learn/utils/multiclass.py in type_of_target(y)
403
404     if not valid:
--> 405         raise ValueError(f'Expected array-like (array or non-string sequence), got {y}')
406
407     sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])

ValueError: Expected array-like (array or non-string sequence), got 159615    0
134010    0
199100    0
137756    0
200050    0
..
219880    0
82326     0
184439    0
198518    0
109959    0
Name: label_bigint, Length: 1146788, dtype: int64

# Fixed code
def __mars_tensor__(self, dtype=None, order="K"):
    return self._data.__mars_tensor__(dtype=dtype, order=order)
# Buggy code
def __mars_tensor__(self, dtype=None, order="K"):
    return self._data.to_tensor().astype(dtype=dtype, order=order, copy=False)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-f2912f2e33a0> in <module>
1 from mars.learn.metrics import accuracy_score
----> 2 accuracy_score(y_test,y_pred).execute()

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight, session, run_kwargs)
178     op = AccuracyScore(y_true=y_true, y_pred=y_pred, normalize=normalize,
179                        sample_weight=sample_weight)
--> 180     score = op(y_true, y_pred)
181     return score.execute(session=session, **(run_kwargs or dict()))

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in __call__(self, y_true, y_pred)
76
77     def __call__(self, y_true, y_pred):
---> 78         type_true, y_true, y_pred = _check_targets(y_true, y_pred)
79         self._type_true = type_true
80         inputs = [y_true, y_pred, type_true]

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in _check_targets(y_true, y_pred)
193     """
194     op = CheckTargets(y_true=y_true, y_pred=y_pred)
--> 195     return op(y_true, y_pred)

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in __call__(self, y_true, y_pred)
82         if isinstance(y_pred, (Base, Entity)):
83             inputs.append(y_pred)
---> 84         self._type_true = type_of_target(y_true)
85         self._type_pred = type_of_target(y_pred)
86         inputs.extend([self._type_true, self._type_pred])

/home/tops/lib/python3.6/site-packages/mars/learn/utils/multiclass.py in type_of_target(y)
403
404     if not valid:
--> 405         raise ValueError(f'Expected array-like (array or non-string sequence), got {y}')
406
407     sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])

ValueError: Expected array-like (array or non-string sequence), got 159615    0
134010    0
199100    0
137756    0
200050    0
..
219880    0
82326     0
184439    0
198518    0
109959    0
Name: label_bigint, Length: 1146788, dtype: int64

# Fixed code
def __mars_tensor__(self, dtype=None, order="K"):
    return self._data.__mars_tensor__(dtype=dtype, order=order)
# Buggy code
def _to_mars_tensor(self, dtype=None, order="K", extract_multi_index=False):
    tensor = self._data.to_tensor(extract_multi_index=extract_multi_index)
    dtype = dtype if dtype is not None else tensor.dtype
    return tensor.astype(dtype=dtype, order=order, copy=False)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-f2912f2e33a0> in <module>
1 from mars.learn.metrics import accuracy_score
----> 2 accuracy_score(y_test,y_pred).execute()

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight, session, run_kwargs)
178     op = AccuracyScore(y_true=y_true, y_pred=y_pred, normalize=normalize,
179                        sample_weight=sample_weight)
--> 180     score = op(y_true, y_pred)
181     return score.execute(session=session, **(run_kwargs or dict()))

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in __call__(self, y_true, y_pred)
76
77     def __call__(self, y_true, y_pred):
---> 78         type_true, y_true, y_pred = _check_targets(y_true, y_pred)
79         self._type_true = type_true
80         inputs = [y_true, y_pred, type_true]

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in _check_targets(y_true, y_pred)
193     """
194     op = CheckTargets(y_true=y_true, y_pred=y_pred)
--> 195     return op(y_true, y_pred)

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in __call__(self, y_true, y_pred)
82         if isinstance(y_pred, (Base, Entity)):
83             inputs.append(y_pred)
---> 84         self._type_true = type_of_target(y_true)
85         self._type_pred = type_of_target(y_pred)
86         inputs.extend([self._type_true, self._type_pred])

/home/tops/lib/python3.6/site-packages/mars/learn/utils/multiclass.py in type_of_target(y)
403
404     if not valid:
--> 405         raise ValueError(f'Expected array-like (array or non-string sequence), got {y}')
406
407     sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])

ValueError: Expected array-like (array or non-string sequence), got 159615    0
134010    0
199100    0
137756    0
200050    0
..
219880    0
82326     0
184439    0
198518    0
109959    0
Name: label_bigint, Length: 1146788, dtype: int64

# Fixed code
def _to_mars_tensor(self, dtype=None, order="K", extract_multi_index=False):
    tensor = self.to_tensor(extract_multi_index=extract_multi_index)
    dtype = dtype if dtype is not None else tensor.dtype
    return tensor.astype(dtype=dtype, order=order, copy=False)
# Buggy code
def __init__(self, n_workers=None, output_types=None, **kw):
    super().__init__(_n_workers=n_workers, _output_types=output_types, **kw)
    if self.output_types is None:
        self.output_types = [OutputType.object]


# Traceback (TimeoutError)
2021-01-26 15:39:43,801 mars.scheduler.operands.base 474 DEBUG    Operand e3036e9fb2b4f84911306f8fa9cf3e03(StartTracker) state from OperandState.UNSCHEDULED to OperandState.READY.
2021-01-26 15:39:43,802 mars.scheduler.assigner 476 DEBUG    Operand e3036e9fb2b4f84911306f8fa9cf3e03 enqueued

2021-01-26 15:49:43,403 mars.scheduler.assigner 473 ERROR    Unexpected exception occurred in AssignEvaluationActor._allocate_resource. op_key=e3036e9fb2b4f84911306f8fa9cf3e03
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out
2021-01-26 15:49:43,404 mars.scheduler.assigner 473 ERROR    Unexpected error occurred in s:0:AssignEvaluationActor$eb2a35c62f8cfb405cc15245e0d1cf02
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 315, in allocate_top_resources
reject_workers=reject_workers)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out
2021-01-26 15:49:43,407 mars.scheduler.operands.common 474 ERROR    Attempt 1: Unexpected error TimeoutError occurred in executing operand e3036e9fb2b4f84911306f8fa9cf3e03 in None
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 315, in allocate_top_resources
reject_workers=reject_workers)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out

# Fixed code
def __init__(self, n_workers=None, output_types=None, pure_depends=None, **kw):
    super().__init__(
        _n_workers=n_workers,
        _output_types=output_types,
        _pure_depends=pure_depends,
        **kw,
    )
    if self.output_types is None:
        self.output_types = [OutputType.object]