gurudesh/pytracebugs huggingface dataset:
# Buggy code
def init_job_queue():
    if WORK_MODE == WorkMode.STANDALONE:
        job_queue = InProcessQueue()
        RuntimeConfig.init_config(JOB_QUEUE=job_queue)
    elif WORK_MODE == WorkMode.CLUSTER:
        job_queue = RedisQueue(
            queue_name="fate_flow_job_queue",
            host=REDIS["host"],
            port=REDIS["port"],
            password=REDIS["password"],
            max_connections=REDIS["max_connections"],
        )
        RuntimeConfig.init_config(JOB_QUEUE=job_queue)
    else:
        raise Exception("init queue failed.")


# Traceback (ImportError)
stdout:Traceback (most recent call last):
File "/home/wy/FATE/examples/federatedml-1.0-examples/../../fate_flow/fate_flow_client.py", line 17, in <module>
import argparse
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/argparse.py", line 86, in <module>
import collections as _collections
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/collections/__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'

# Fixed code
def init_job_queue():
    if RuntimeConfig.WORK_MODE == WorkMode.STANDALONE:
        job_queue = InProcessQueue()
        RuntimeConfig.init_config(JOB_QUEUE=job_queue)
    elif RuntimeConfig.WORK_MODE == WorkMode.CLUSTER:
        job_queue = RedisQueue(
            queue_name="fate_flow_job_queue",
            host=REDIS["host"],
            port=REDIS["port"],
            password=REDIS["password"],
            max_connections=REDIS["max_connections"],
        )
        RuntimeConfig.init_config(JOB_QUEUE=job_queue)
    else:
        raise Exception("init queue failed.")
# Buggy code
def local_api(method, endpoint, json_body):
    try:
        stat_logger.info("local api request: {}".format(endpoint))
        url = "{}{}".format(SERVER_HOST_URL, endpoint)
        action = getattr(requests, method.lower(), None)
        response = action(url=url, json=json_body, headers=HEADERS)
        stat_logger.info(response.text)
        response_json_body = response.json()
        stat_logger.info(
            "local api response: {} {}".format(endpoint, response_json_body)
        )
        return response_json_body
    except Exception as e:
        raise Exception("local request error: {}".format(e))


# Traceback (ImportError)
stdout:Traceback (most recent call last):
File "/home/wy/FATE/examples/federatedml-1.0-examples/../../fate_flow/fate_flow_client.py", line 17, in <module>
import argparse
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/argparse.py", line 86, in <module>
import collections as _collections
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/collections/__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'

# Fixed code
def local_api(method, endpoint, json_body):
    try:
        url = "http://{}{}".format(RuntimeConfig.JOB_SERVER_HOST, endpoint)
        stat_logger.info("local api request: {}".format(url))
        action = getattr(requests, method.lower(), None)
        response = action(url=url, json=json_body, headers=HEADERS)
        stat_logger.info(response.text)
        response_json_body = response.json()
        stat_logger.info(
            "local api response: {} {}".format(endpoint, response_json_body)
        )
        return response_json_body
    except Exception as e:
        raise Exception("local request error: {}".format(e))
# Buggy code
def check_config(config: typing.Dict, required_arguments: typing.List):
    no_arguments = []
    error_arguments = []
    for argument in required_arguments:
        if isinstance(argument, tuple):
            if config.get(argument[0], None) != argument[1]:
                error_arguments.append(argument)
        elif argument not in config:
            no_arguments.append(argument)
    if no_arguments or error_arguments:
        raise Exception(
            "the following arguments are required: {} {}".format(
                ",".join(no_arguments),
                ",".join(["{}={}".format(a[0], a[1]) for a in error_arguments]),
            )
        )


# Traceback (ImportError)
stdout:Traceback (most recent call last):
File "/home/wy/FATE/examples/federatedml-1.0-examples/../../fate_flow/fate_flow_client.py", line 17, in <module>
import argparse
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/argparse.py", line 86, in <module>
import collections as _collections
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/collections/__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'

# Fixed code
def check_config(config: typing.Dict, required_arguments: typing.List):
    no_arguments = []
    error_arguments = []
    for require_argument in required_arguments:
        if isinstance(require_argument, tuple):
            config_value = config.get(require_argument[0], None)
            if isinstance(require_argument[1], (tuple, list)):
                if config_value not in require_argument[1]:
                    error_arguments.append(require_argument)
            elif config_value != require_argument[1]:
                error_arguments.append(require_argument)
        elif require_argument not in config:
            no_arguments.append(require_argument)
    if no_arguments or error_arguments:
        raise Exception(
            "the following arguments are required: {} {}".format(
                ",".join(no_arguments),
                ",".join(["{}={}".format(a[0], a[1]) for a in error_arguments]),
            )
        )
# Buggy code
def get_url(_suffix):
    return "{}/{}".format(SERVER_HOST_URL.rstrip("/"), _suffix.lstrip("/"))


# Traceback (ImportError)
stdout:Traceback (most recent call last):
File "/home/wy/FATE/examples/federatedml-1.0-examples/../../fate_flow/fate_flow_client.py", line 17, in <module>
import argparse
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/argparse.py", line 86, in <module>
import collections as _collections
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/collections/__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'

# Fixed code
def get_url(_suffix):
    return "http://{}/{}".format(
        RuntimeConfig.JOB_SERVER_HOST.rstrip("/"), _suffix.lstrip("/")
    )
# Buggy code
def check_pipeline_job_runtime_conf(runtime_conf: typing.Dict):
    detect_utils.check_config(runtime_conf, ["initiator", "job_parameters", "role"])
    detect_utils.check_config(runtime_conf["initiator"], ["role", "party_id"])
    detect_utils.check_config(
        runtime_conf["job_parameters"], [("work_mode", WORK_MODE)]
    )
    # deal party id
    runtime_conf["initiator"]["party_id"] = int(runtime_conf["initiator"]["party_id"])
    for r in runtime_conf["role"].keys():
        for i in range(len(runtime_conf["role"][r])):
            runtime_conf["role"][r][i] = int(runtime_conf["role"][r][i])


# Traceback (ImportError)
stdout:Traceback (most recent call last):
File "/home/wy/FATE/examples/federatedml-1.0-examples/../../fate_flow/fate_flow_client.py", line 17, in <module>
import argparse
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/argparse.py", line 86, in <module>
import collections as _collections
File "/home/wy/.pyenv/versions/3.6.0/lib/python3.6/collections/__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'

# Fixed code
def check_pipeline_job_runtime_conf(runtime_conf: typing.Dict):
    detect_utils.check_config(runtime_conf, ["initiator", "job_parameters", "role"])
    detect_utils.check_config(runtime_conf["initiator"], ["role", "party_id"])
    detect_utils.check_config(
        runtime_conf["job_parameters"], [("work_mode", RuntimeConfig.WORK_MODE)]
    )
    # deal party id
    runtime_conf["initiator"]["party_id"] = int(runtime_conf["initiator"]["party_id"])
    for r in runtime_conf["role"].keys():
        for i in range(len(runtime_conf["role"][r])):
            runtime_conf["role"][r][i] = int(runtime_conf["role"][r][i])
# Buggy code
def save_episodes_as_file(self, episodes):
    PRIVATE_FOLDER_ATTRIBUTE = "_save_episodes_as_file_folder"
    folder = getattr(self, PRIVATE_FOLDER_ATTRIBUTE, None)
    (notCancelled, folder) = self.show_folder_select_dialog(initial_directory=folder)
    setattr(self, PRIVATE_FOLDER_ATTRIBUTE, folder)

    if notCancelled:
        for episode in episodes:
            if episode.was_downloaded(and_exists=True):
                copy_from = episode.local_filename(create=False)
                assert copy_from is not None

                base, extension = os.path.splitext(copy_from)
                filename = self.build_filename(episode.sync_filename(), extension)
                copy_to = os.path.join(folder, filename)
                shutil.copyfile(copy_from, copy_to)


# Traceback (OSError)
1492734407.836906 [gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
File "/home/user/dev/gpodder/src/gpodder/gtkui/main.py", line 1750, in save_episodes_as_file
shutil.copyfile(copy_from, copy_to)
File "/usr/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: '/media/user/0123-4567/Podcasts/Episode 84: Ur Fave is Problematic.mp3'

Traceback (most recent call last):
File "/home/user/dev/gpodder/src/gpodder/gtkui/main.py", line 1750, in save_episodes_as_file
shutil.copyfile(copy_from, copy_to)
File "/usr/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: '/media/user/0123-4567/Podcasts/Episode 84: Ur Fave is Problematic.mp3'

# Fixed code
def save_episodes_as_file(self, episodes):
    PRIVATE_FOLDER_ATTRIBUTE = "_save_episodes_as_file_folder"
    folder = getattr(self, PRIVATE_FOLDER_ATTRIBUTE, None)
    (notCancelled, folder) = self.show_folder_select_dialog(initial_directory=folder)
    setattr(self, PRIVATE_FOLDER_ATTRIBUTE, folder)

    if notCancelled:
        for episode in episodes:
            if episode.was_downloaded(and_exists=True):
                copy_from = episode.local_filename(create=False)
                assert copy_from is not None

                base, extension = os.path.splitext(copy_from)
                filename = self.build_filename(episode.sync_filename(), extension)
                copy_to = os.path.join(folder, filename)
                try:
                    shutil.copyfile(copy_from, copy_to)
                except (OSError, IOError) as e:
                    # Remove characters not supported by VFAT (#282)
                    new_filename = re.sub(r"[\"*/:<>?\\|]", "_", filename)
                    destination = os.path.join(folder, new_filename)
                    if copy_to != destination:
                        shutil.copyfile(copy_from, destination)
                    else:
                        raise
# Buggy code
def _split_credentials(
    credentials: Union[Dict[str, Any], None],
) -> Tuple[Dict[str, Any], Any]:
    credentials = deepcopy(credentials) or {}
    dataset_credentials = credentials.pop(
        DATASET_CREDENTIALS_KEY, deepcopy(credentials)
    )
    return credentials, dataset_credentials


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def _split_credentials(
    credentials: Union[Dict[str, Any], None],
) -> Tuple[Dict[str, Any], Any]:
    credentials = deepcopy(credentials) or {}
    if DATASET_CREDENTIALS_KEY in credentials:
        warn(
            "Support for `{}` key in the credentials is now deprecated and will be "
            "removed in the next version. Please specify the dataset credentials "
            "explicitly inside the dataset config.".format(DATASET_CREDENTIALS_KEY),
            DeprecationWarning,
        )
        dataset_credentials = credentials.pop(DATASET_CREDENTIALS_KEY)
    else:
        dataset_credentials = deepcopy(credentials)
    return credentials, dataset_credentials
# Buggy code
def _list_partitions(self) -> List[str]:
    return [
        path
        for path in self._filesystem.find(self._path, **self._load_args)
        if path.endswith(self._filename_suffix)
    ]


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def _list_partitions(self) -> List[str]:
    checkpoint = self._read_checkpoint()
    checkpoint_path = self._filesystem._strip_protocol(  # pylint: disable=protected-access
        self._checkpoint_config[self._filepath_arg]
    )

    def _is_valid_partition(partition) -> bool:
        if not partition.endswith(self._filename_suffix):
            return False
        if partition == checkpoint_path:
            return False
        if checkpoint is None:
            # nothing was processed yet
            return True
        partition_id = self._path_to_partition(partition)
        return self._comparison_func(partition_id, checkpoint)

    return [
        part
        for part in sorted(self._filesystem.find(self._path, **self._load_args))
        if _is_valid_partition(part)
    ]
# Buggy code
def _load(self) -> Dict[str, Callable[[], Any]]:
    partitions = {}

    for partition in self._list_partitions():
        kwargs = deepcopy(self._dataset_config)
        # join the protocol back since PySpark may rely on it
        kwargs[self._filepath_arg] = self._join_protocol(partition)
        dataset = self._dataset_type(**kwargs)  # type: ignore
        partition_id = self._path_to_partition(partition)
        partitions[partition_id] = dataset.load

    if not partitions:
        raise DataSetError("No partitions found in `{}`".format(self._path))

    return partitions


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def _load(self) -> Dict[str, Callable[[], Any]]:
    partitions = {}

    for partition in self._list_partitions():
        partition_id = self._path_to_partition(partition)
        kwargs = deepcopy(self._dataset_config)
        # join the protocol back since PySpark may rely on it
        kwargs[self._filepath_arg] = self._join_protocol(partition)
        partitions[partition_id] = self._dataset_type(  # type: ignore
            **kwargs
        ).load()

    return partitions
# Buggy code
def _copy(self, **overwrite_params):
    """
    Helper function to copy the node, replacing some values.
    """
    params = {
        "func": self._func,
        "inputs": self._inputs,
        "outputs": self._outputs,
        "name": self._name,
        "tags": self._tags,
        "decorators": self._decorators,
    }
    params.update(overwrite_params)
    return Node(**params)


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def _copy(self, **overwrite_params):
    """
    Helper function to copy the node, replacing some values.
    """
    params = {
        "func": self._func,
        "inputs": self._inputs,
        "outputs": self._outputs,
        "name": self._name,
        "tags": self._tags,
        "decorators": self._decorators,
        "confirms": self._confirms,
    }
    params.update(overwrite_params)
    return Node(**params)
# Buggy code
def _validate_unique_outputs(nodes: List[Node]) -> None:
    outputs_list = list(chain.from_iterable(node.outputs for node in nodes))
    outputs_list = [_get_transcode_compatible_name(o) for o in outputs_list]
    counter_list = Counter(outputs_list)
    counter_set = Counter(set(outputs_list))
    diff = counter_list - counter_set
    if diff:
        raise OutputNotUniqueError(
            "Output(s) {} are returned by "
            "more than one nodes. Node "
            "outputs must be unique.".format(sorted(diff.keys()))
        )


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def _validate_unique_outputs(nodes: List[Node]) -> None:
    outputs = chain.from_iterable(node.outputs for node in nodes)
    outputs = map(_get_transcode_compatible_name, outputs)
    duplicates = [key for key, value in Counter(outputs).items() if value > 1]
    if duplicates:
        raise OutputNotUniqueError(
            "Output(s) {} are returned by more than one nodes. Node "
            "outputs must be unique.".format(sorted(duplicates))
        )
# Buggy code
def run_node(node: Node, catalog: DataCatalog) -> Node:
    """Run a single `Node` with inputs from and outputs to the `catalog`.

    Args:
        node: The ``Node`` to run.
        catalog: A ``DataCatalog`` containing the node's inputs and outputs.

    Returns:
        The node argument.

    """
    inputs = {name: catalog.load(name) for name in node.inputs}
    outputs = node.run(inputs)
    for name, data in outputs.items():
        catalog.save(name, data)
    return node


# Traceback (AttributeError)
/home/markf94/.../kedro-project/.venv/bin/python -m piptools compile /home/markf94/.../kedro-project/src/requirements.in
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/__main__.py", line 17, in <module>
cli()
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/markf94.../kedro-project/.venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/scripts/compile.py", line 304, in cli
for ireq in filter(is_pinned_requirement, ireqs):
File "/home/markf94/.../kedro-project/.venv/lib/python3.7/site-packages/piptools/utils.py", line 122, in is_pinned_requirement
if ireq.editable:
AttributeError: 'ParsedRequirement' object has no attribute 'editable'

# Fixed code
def run_node(node: Node, catalog: DataCatalog) -> Node:
    """Run a single `Node` with inputs from and outputs to the `catalog`.

    Args:
        node: The ``Node`` to run.
        catalog: A ``DataCatalog`` containing the node's inputs and outputs.

    Returns:
        The node argument.

    """
    inputs = {name: catalog.load(name) for name in node.inputs}
    outputs = node.run(inputs)
    for name, data in outputs.items():
        catalog.save(name, data)
    for name in node.confirms:
        catalog.confirm(name)
    return node
# Buggy code
def set_cell_anchors(self, dtype, device):
    # type: (int, Device) -> None    # noqa: F821
    if self.cell_anchors is not None:
        return

    cell_anchors = [
        self.generate_anchors(sizes, aspect_ratios, dtype, device)
        for sizes, aspect_ratios in zip(self.sizes, self.aspect_ratios)
    ]
    self.cell_anchors = cell_anchors


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/home/ubrdog/PycharmProjects/FacialDetection/bug_replication.py", line 17, in <module>
out_data2 = model(dummy_data)
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torch/nn/modules/module.py", line 539, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torchvision-0.5.0a0+61763fa-py3.7-linux-x86_64.egg/torchvision/models/detection/generalized_rcnn.py", line 70, in forward
proposals, proposal_losses = self.rpn(images, features, targets)
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torch/nn/modules/module.py", line 539, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torchvision-0.5.0a0+61763fa-py3.7-linux-x86_64.egg/torchvision/models/detection/rpn.py", line 472, in forward
proposals = self.box_coder.decode(pred_bbox_deltas.detach(), anchors)
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torchvision-0.5.0a0+61763fa-py3.7-linux-x86_64.egg/torchvision/models/detection/_utils.py", line 187, in decode
rel_codes.reshape(box_sum, -1), concat_boxes
File "/home/ubrdog/miniconda3/envs/FacialDetection/lib/python3.7/site-packages/torchvision-0.5.0a0+61763fa-py3.7-linux-x86_64.egg/torchvision/models/detection/_utils.py", line 218, in decode_single
pred_ctr_x = dx * widths[:, None] + ctr_x[:, None]
RuntimeError: expected device cpu but got device cuda:0

# Fixed code
def set_cell_anchors(self, dtype, device):
    # type: (int, Device) -> None    # noqa: F821
    if self.cell_anchors is not None:
        cell_anchors = self.cell_anchors
        assert cell_anchors is not None
        # suppose that all anchors have the same device
        # which is a valid assumption in the current state of the codebase
        if cell_anchors[0].device == device:
            return

    cell_anchors = [
        self.generate_anchors(sizes, aspect_ratios, dtype, device)
        for sizes, aspect_ratios in zip(self.sizes, self.aspect_ratios)
    ]
    self.cell_anchors = cell_anchors
# Buggy code
def __repr__(self):
    head = "Dataset " + self.__class__.__name__
    body = ["Number of datapoints: {}".format(self.__len__())]
    if self.root is not None:
        body.append("Root location: {}".format(self.root))
    body += self.extra_repr().splitlines()
    if self.transforms is not None:
        body += [repr(self.transforms)]
    lines = [head] + [" " * self._repr_indent + line for line in body]
    return "\n".join(lines)


# Traceback (AttributeError)
In [1]: from torchvision.datasets import STL10

In [2]: data = STL10("Documents/dataset", download=True)
Files already downloaded and verified

In [3]: print(data)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-dbd883db58b7> in <module>
----> 1 print(data)

~/pythonenvs/bentley/lib/python3.7/site-packages/torchvision/datasets/vision.py in __repr__(self)
38             body.append("Root location: {}".format(self.root))
39         body += self.extra_repr().splitlines()
---> 40         if self.transforms is not None:
41             body += [repr(self.transforms)]
42         lines = [head] + [" " * self._repr_indent + line for line in body]

AttributeError: 'STL10' object has no attribute 'transforms'

# Fixed code
def __repr__(self):
    head = "Dataset " + self.__class__.__name__
    body = ["Number of datapoints: {}".format(self.__len__())]
    if self.root is not None:
        body.append("Root location: {}".format(self.root))
    body += self.extra_repr().splitlines()
    if hasattr(self, "transforms") and self.transforms is not None:
        body += [repr(self.transforms)]
    lines = [head] + [" " * self._repr_indent + line for line in body]
    return "\n".join(lines)
# Buggy code
def resolve_host(self):
    optional = [
        item
        for item in self.OPTIONAL_HOSTS
        if item in self.config and self.config[item] != "none"
    ]
    for item in list(self.HOSTS) + optional:
        host = "HOST_" + item
        self.config[host] = system.resolve_address(self.config[host])


# Traceback (ConnectionError)
mailu_admin| [2019-01-25 14:15:37,610] ERROR in app: Exception on /internal/auth/email [GET]
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 493, in connect
mailu_admin|     sock = self._connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 520, in _connect
mailu_admin|     socket.SOCK_STREAM):
mailu_admin|   File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
mailu_admin|     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
mailu_admin| socket.gaierror: [Errno -2] Name does not resolve

mailu_admin| During handling of the above exception, another exception occurred:
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/client.py", line 754, in execute_command
mailu_admin|     connection.send_command(*args)
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 619, in send_command
mailu_admin|     self.send_packed_command(self.pack_command(*args))
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 594, in send_packed_command
mailu_admin|     self.connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 498, in connect
mailu_admin|     raise ConnectionError(self._error_message(e))
mailu_admin| redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name does not resolve.

# Fixed code
def resolve_host(self):
    optional = [
        item
        for item in self.OPTIONAL_HOSTS
        if item in self.config and self.config[item] != "none"
    ]
    for item in list(self.HOSTS) + optional:
        host = "HOST_" + item
        address = item + "_ADDRESS"
        self.config[address] = system.resolve_address(self.config[host])
# Buggy code
def init_app(self, app):
    self.config.update(app.config)
    # get environment variables
    self.config.update(
        {
            key: self.__coerce_value(os.environ.get(key, value))
            for key, value in DEFAULT_CONFIG.items()
        }
    )
    self.resolve_host()

    # automatically set the sqlalchemy string
    if self.config["DB_FLAVOR"]:
        template = self.DB_TEMPLATES[self.config["DB_FLAVOR"]]
        self.config["SQLALCHEMY_DATABASE_URI"] = template.format(**self.config)
    # update the app config itself
    app.config = self


# Traceback (ConnectionError)
mailu_admin| [2019-01-25 14:15:37,610] ERROR in app: Exception on /internal/auth/email [GET]
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 493, in connect
mailu_admin|     sock = self._connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 520, in _connect
mailu_admin|     socket.SOCK_STREAM):
mailu_admin|   File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
mailu_admin|     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
mailu_admin| socket.gaierror: [Errno -2] Name does not resolve

mailu_admin| During handling of the above exception, another exception occurred:
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/client.py", line 754, in execute_command
mailu_admin|     connection.send_command(*args)
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 619, in send_command
mailu_admin|     self.send_packed_command(self.pack_command(*args))
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 594, in send_packed_command
mailu_admin|     self.connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 498, in connect
mailu_admin|     raise ConnectionError(self._error_message(e))
mailu_admin| redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name does not resolve.

# Fixed code
def init_app(self, app):
    self.config.update(app.config)
    # get environment variables
    self.config.update(
        {
            key: self.__coerce_value(os.environ.get(key, value))
            for key, value in DEFAULT_CONFIG.items()
        }
    )
    self.resolve_host()

    # automatically set the sqlalchemy string
    if self.config["DB_FLAVOR"]:
        template = self.DB_TEMPLATES[self.config["DB_FLAVOR"]]
        self.config["SQLALCHEMY_DATABASE_URI"] = template.format(**self.config)

    self.config["RATELIMIT_STORAGE_URL"] = "redis://{0}/2".format(
        self.config["REDIS_ADDRESS"]
    )
    self.config["QUOTA_STORAGE_URL"] = "redis://{0}/1".format(
        self.config["REDIS_ADDRESS"]
    )
    # update the app config itself
    app.config = self
# Buggy code
def get_server(protocol, authenticated=False):
    if protocol == "imap":
        hostname, port = extract_host_port(app.config["HOST_IMAP"], 143)
    elif protocol == "pop3":
        hostname, port = extract_host_port(app.config["HOST_POP3"], 110)
    elif protocol == "smtp":
        if authenticated:
            hostname, port = extract_host_port(app.config["HOST_AUTHSMTP"], 10025)
        else:
            hostname, port = extract_host_port(app.config["HOST_SMTP"], 25)
    return hostname, port


# Traceback (ConnectionError)
mailu_admin| [2019-01-25 14:15:37,610] ERROR in app: Exception on /internal/auth/email [GET]
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 493, in connect
mailu_admin|     sock = self._connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 520, in _connect
mailu_admin|     socket.SOCK_STREAM):
mailu_admin|   File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
mailu_admin|     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
mailu_admin| socket.gaierror: [Errno -2] Name does not resolve

mailu_admin| During handling of the above exception, another exception occurred:
mailu_admin| Traceback (most recent call last):
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/client.py", line 754, in execute_command
mailu_admin|     connection.send_command(*args)
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 619, in send_command
mailu_admin|     self.send_packed_command(self.pack_command(*args))
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 594, in send_packed_command
mailu_admin|     self.connect()
mailu_admin|   File "/usr/lib/python3.6/site-packages/redis/connection.py", line 498, in connect
mailu_admin|     raise ConnectionError(self._error_message(e))
mailu_admin| redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name does not resolve.

# Fixed code
def get_server(protocol, authenticated=False):
    if protocol == "imap":
        hostname, port = extract_host_port(app.config["IMAP_ADDRESS"], 143)
    elif protocol == "pop3":
        hostname, port = extract_host_port(app.config["POP3_ADDRESS"], 110)
    elif protocol == "smtp":
        if authenticated:
            hostname, port = extract_host_port(app.config["AUTHSMTP_ADDRESS"], 10025)
        else:
            hostname, port = extract_host_port(app.config["SMTP_ADDRESS"], 25)
    return hostname, port
# Buggy code
def domain(domain_name, max_users=-1, max_aliases=-1, max_quota_bytes=0):
    domain = models.Domain.query.get(domain_name)
    if not domain:
        domain = models.Domain(name=domain_name)
        db.session.add(domain)
        db.session.commit()


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "manage.py", line 1, in <module>
from mailu import models
ModuleNotFoundError: No module named 'mailu'

# Fixed code
def domain(domain_name, max_users=-1, max_aliases=-1, max_quota_bytes=0):
    """Create a domain"""
    domain = models.Domain.query.get(domain_name)
    if not domain:
        domain = models.Domain(name=domain_name)
        db.session.add(domain)
        db.session.commit()
# Buggy code
def prompt_for_config(context, no_input=False):
    """
    Prompts the user to enter new config, using context as a source for the
    field names and sample values.

    :param no_input: Prompt the user at command line for manual configuration?
    """
    cookiecutter_dict = {}
    env = Environment()

    for key, raw in iteritems(context["cookiecutter"]):
        val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)

        if not no_input:
            prompt = '{0} (default is "{1}")? '.format(key, val)

            new_val = read_response(prompt).strip()

            if new_val != "":
                val = new_val

        cookiecutter_dict[key] = val
    return cookiecutter_dict


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/boxen/homebrew/bin/cookiecutter", line 9, in <module>
load_entry_point('cookiecutter==0.9.0', 'console_scripts', 'cookiecutter')()
File "/opt/boxen/homebrew/lib/python2.7/site-packages/cookiecutter/main.py", line 169, in main
cookiecutter(args.input_dir, args.checkout, args.no_input)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/cookiecutter/main.py", line 100, in cookiecutter
context['cookiecutter'] = prompt_for_config(context, no_input)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/cookiecutter/prompt.py", line 29, in prompt_for_config
val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/jinja2/environment.py", line 841, in from_string
return cls.from_code(self, self.compile(source), globals, None)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/jinja2/environment.py", line 542, in compile
source = optimize(source, self)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/jinja2/optimizer.py", line 27, in optimize
return optimizer.visit(node)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/jinja2/visitor.py", line 39, in visit
return self.generic_visit(node, *args, **kwargs)
File "/opt/boxen/homebrew/lib/python2.7/site-packages/jinja2/visitor.py", line 59, in generic_visit
for field, old_value in node.iter_fields():
AttributeError: 'int' object has no attribute 'iter_fields'

# Fixed code
def prompt_for_config(context, no_input=False):
    """
    Prompts the user to enter new config, using context as a source for the
    field names and sample values.

    :param no_input: Prompt the user at command line for manual configuration?
    """
    cookiecutter_dict = {}
    env = Environment()

    for key, raw in iteritems(context["cookiecutter"]):
        val = env.from_string(str(raw)).render(cookiecutter=cookiecutter_dict)

        if not no_input:
            prompt = '{0} (default is "{1}")? '.format(key, val)

            new_val = read_response(prompt).strip()

            if new_val != "":
                val = new_val

        cookiecutter_dict[key] = val
    return cookiecutter_dict
# Buggy code
def __init__(self, adata: Optional[AnnData] = None, use_cuda=False):
    if adata is not None:
        if "_scvi" not in adata.uns.keys():
            raise ValueError(
                "Please setup your AnnData with scvi.data.setup_anndata(adata) first"
            )
        self.adata = adata
        self.scvi_setup_dict_ = adata.uns["_scvi"]
        self.summary_stats = self.scvi_setup_dict_["summary_stats"]
        self._validate_anndata(adata, copy_if_view=False)

    self.is_trained_ = False
    self.use_cuda = use_cuda and torch.cuda.is_available()
    self._model_summary_string = ""
    self.train_indices_ = None
    self.test_indices_ = None
    self.validation_indices_ = None


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-125-eb1e0fcfe1d1> in <module>
1 de = model.differential_expression(
----> 2     groupby="leiden",
3 )
4 de.head()

~/anaconda3/lib/python3.7/site-packages/scvi/core/models/rnamixin.py in differential_expression(self, adata, groupby, group1, group2, idx1, idx2, mode, delta, batch_size, all_stats, batch_correction, batchid1, batchid2, **kwargs)
179         adata = self._validate_anndata(adata)
180
--> 181         col_names = _get_var_names_from_setup_anndata(adata)
182         model_fn = partial(
183             self.get_normalized_expression,

~/anaconda3/lib/python3.7/site-packages/scvi/model/_utils.py in _get_var_names_from_setup_anndata(adata)
119         adata.var_names
120         if adata.uns["_scvi"]["use_raw"] is False
--> 121         else adata.raw.var_names
122     )
123

AttributeError: 'NoneType' object has no attribute 'var_names'

# Fixed code
def __init__(self, adata: Optional[AnnData] = None, use_cuda=False):
    if adata is not None:
        if "_scvi" not in adata.uns.keys():
            raise ValueError(
                "Please setup your AnnData with scvi.data.setup_anndata(adata) first"
            )
        self.adata = adata
        self.scvi_setup_dict_ = adata.uns["_scvi"]
        self.summary_stats = self.scvi_setup_dict_["summary_stats"]
        self._validate_anndata(adata, copy_if_view=False)

    self.is_trained_ = False
    self.use_cuda = use_cuda and torch.cuda.is_available()
    self._model_summary_string = ""
    self.train_indices_ = None
    self.test_indices_ = None
    self.validation_indices_ = None
    self.history_ = None
# Buggy code
def history(self):
    """Returns computed metrics during training."""
    if self.is_trained_ is False:
        return {}
    return self.trainer.history


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-125-eb1e0fcfe1d1> in <module>
1 de = model.differential_expression(
----> 2     groupby="leiden",
3 )
4 de.head()

~/anaconda3/lib/python3.7/site-packages/scvi/core/models/rnamixin.py in differential_expression(self, adata, groupby, group1, group2, idx1, idx2, mode, delta, batch_size, all_stats, batch_correction, batchid1, batchid2, **kwargs)
179         adata = self._validate_anndata(adata)
180
--> 181         col_names = _get_var_names_from_setup_anndata(adata)
182         model_fn = partial(
183             self.get_normalized_expression,

~/anaconda3/lib/python3.7/site-packages/scvi/model/_utils.py in _get_var_names_from_setup_anndata(adata)
119         adata.var_names
120         if adata.uns["_scvi"]["use_raw"] is False
--> 121         else adata.raw.var_names
122     )
123

AttributeError: 'NoneType' object has no attribute 'var_names'

# Fixed code
def history(self):
    """Returns computed metrics during training."""
    return self.history_