internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: robocorp/rpaframework

Issue:
`RPA.PDF` Investigate fields setting bug
`IndexError` coming from `pypdf` when calling `Save Field Values`.

Slack [thread](https://robocorp-developers.slack.com/archives/CVBU007LN/p1676943504960429)


Discussion:

Resolving patch:
diff --git a/packages/pdf/src/RPA/PDF/keywords/model.py b/packages/pdf/src/RPA/PDF/keywords/model.py
--- a/packages/pdf/src/RPA/PDF/keywords/model.py
+++ b/packages/pdf/src/RPA/PDF/keywords/model.py
@@ -32,7 +32,8 @@
 
 
 Coords = Tuple[int, ...]
-BOXES_FLOW_NOT_SET = -999.99
+
+BOXES_FLOW_NOT_SET = 0.5
 
 
 def iterable_items_to_ints(bbox: Optional[Iterable]) -> Coords:
@@ -480,7 +481,7 @@ class ModelKeywords(LibraryContext):
     def convert(
         self,
         source_path: Optional[str] = None,
-        trim: Optional[bool] = True,
+        trim: bool = True,
         pagenum: Optional[Union[int, str]] = None,
     ):
         """Parse source PDF into entities.
@@ -582,7 +583,7 @@ def _decode_field(
     def get_input_fields(
         self,
         source_path: Optional[str] = None,
-        replace_none_value: Optional[bool] = False,
+        replace_none_value: bool = False,
         encoding: Optional[str] = FIELDS_ENCODING,
     ) -> dict:
         """Get input fields in the PDF.
@@ -961,5 +962,4 @@ def example_keyword():
             self.ctx.convert_settings["char_margin"] = char_margin
         if word_margin:
             self.ctx.convert_settings["word_margin"] = word_margin
-        if boxes_flow != BOXES_FLOW_NOT_SET:
-            self.ctx.convert_settings["boxes_flow"] = boxes_flow
+        self.ctx.convert_settings["boxes_flow"] = boxes_flow


Test patch:
diff --git a/packages/pdf/tests/python/test_document.py b/packages/pdf/tests/python/test_document.py
--- a/packages/pdf/tests/python/test_document.py
+++ b/packages/pdf/tests/python/test_document.py
@@ -168,14 +168,6 @@ def test_decrypt_pdf(library):
             assert library.is_pdf_encrypted(encrypted_pdf)
 
 
-@pytest.mark.skip(reason="replacing text in PDF is missing")
-def test_replace_text(library):
-    new_text = "a company name"
-    library.replace_text("Test Business", new_text, source_path=TestFiles.invoice_pdf)
-    # TODO: this should replace text in the original PDF
-    # file without breaking anything.
-
-
 def test_get_all_figures(library):
     pages = library.get_all_figures(source_path=TestFiles.vero_pdf)
     figure = pages[1][44]
diff --git a/packages/pdf/tests/robot/test_pdf.robot b/packages/pdf/tests/robot/test_pdf.robot
--- a/packages/pdf/tests/robot/test_pdf.robot
+++ b/packages/pdf/tests/robot/test_pdf.robot
@@ -7,7 +7,7 @@ Library           XML
 Resource          test.resource
 
 Task Teardown     Close all PDFs
-Suite Teardown    Empty Directory    ${WORK_DIR}
+Suite Teardown    Run Keyword And Ignore Error   Empty Directory    ${WORK_DIR}
 
 
 *** Tasks ***
Repository: rlworkgroup/garage

Issue:
Make timestamps in stdout logs less verbose
`2018-07-24 16:44:28.696836 UTC` --> `2018-07-24 16:44:28`

It wastes columns and in practice we don't care about the timezone and don't need microsecond precision.


Discussion:
Note that the text logs sent to file should still have microsecond timestamps and time zones, but the text logs printed to the console should not.

Resolving patch:
diff --git a/garage/misc/logger.py b/garage/misc/logger.py
--- a/garage/misc/logger.py
+++ b/garage/misc/logger.py
@@ -134,15 +134,20 @@ def log(s, with_prefix=True, with_timestamp=True, color=None):
     out = s
     if with_prefix:
         out = _prefix_str + out
+    # out_basic holds output with a simpler timestamp for stdout
+    out_basic = out
     if with_timestamp:
         now = datetime.datetime.now(dateutil.tz.tzlocal())
+        timestamp_basic = now.strftime('%Y-%m-%d %H:%M:%S')
         timestamp = now.strftime('%Y-%m-%d %H:%M:%S.%f %Z')
+        out_basic = "%s | %s" % (timestamp_basic, out_basic)
         out = "%s | %s" % (timestamp, out)
     if color is not None:
         out = colorize(out, color)
+        out_basic = colorize(out_basic, color)
     if not _log_tabular_only:
         # Also log to stdout
-        print(out)
+        print(out_basic)
         for fd in list(_text_fds.values()):
             fd.write(out + '\n')
             fd.flush()


Test patch:
Repository: rlworkgroup/garage

Issue:
Investigate TensorFlow warning in NPO about IndexedSlices
```sh
/home/rjulian/miniconda2/envs/garage-joblib/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py:108: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
  "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
```

I think this has something to do with the design of our loss function in NPO. 

* Determine if we can address the warning
* If we can't address the warning, determine if it's actually a problem
* If it's not a (big) problem, I think we can find a way to suppress it


Discussion:

Resolving patch:
diff --git a/garage/tf/distributions/categorical.py b/garage/tf/distributions/categorical.py
--- a/garage/tf/distributions/categorical.py
+++ b/garage/tf/distributions/categorical.py
@@ -118,5 +118,6 @@ def sample_sym(self, dist_info, name=None):
         with tf.name_scope(name, "sample_sym", [dist_info]):
             probs = dist_info["prob"]
             samples = tf.multinomial(tf.log(probs + 1e-8), num_samples=1)[:, 0]
+
             return tf.nn.embedding_lookup(
                 np.eye(self.dim, dtype=np.float32), samples)
diff --git a/garage/tf/misc/tensor_utils.py b/garage/tf/misc/tensor_utils.py
--- a/garage/tf/misc/tensor_utils.py
+++ b/garage/tf/misc/tensor_utils.py
@@ -23,7 +23,10 @@ def flatten_batch_dict(d, name=None):
 
 
 def filter_valids(t, valid, name="filter_valids"):
-    return tf.boolean_mask(t, valid, name=name)
+    # 'valid' is either 0 or 1 with dtype of tf.float32
+    # Must round before cast to prevent floating-error
+    return tf.dynamic_partition(
+        t, tf.to_int32(tf.round(valid)), 2, name=name)[1]
 
 
 def filter_valids_dict(d, valid, name=None):


Test patch:
Repository: rlworkgroup/garage

Issue:
variable initialization in local_tf_runner is slow and incorrect
The variable initialization code in function `initialize_tf_vars` of `garage/experiment/local_tf_runner.py` is written in a way that's both very inefficient and potentially incorrect. In particular, the list comprehension
````[
                    v for v in tf.global_variables()
                    if v.name.split(':')[0] in str(
                        self.sess.run(tf.report_uninitialized_variables()))
]
````
reruns the `tf.report_uninitialized_variables()` op every time the condition needs to be evaluated, which is very slow for larger graphs. It takes me several minutes to run for a convnet with 128x128x4 pixel inputs. Storing the result of this operation reduces runtime to mere seconds.

Further, the use of string operations can potentially lead to re-initializing some variables. If the name of some initialised variable A is a substring of an uninitialised variable B, the above list comprehension will include variable A in the result. A better alternative is to decode the bytestrings returned by `sess.run(tf.report_uninitialized_variables()` and construct a set.

The function code then becomes

````uninit_set = set(
            e.decode() for e in self.sess.run(tf.report_uninitialized_variables())
        )
        self.sess.run(
            tf.variables_initializer([
                v for v in tf.global_variables()
                if v.name.split(':')[0] in uninit_set
            ]))
````

If this idea seems reasonable, I am happy to make a pull request.


Discussion:
Great catch, thanks for filing the issue.

Can you make a PR? If you are not on North American time, we will probably beat you to it today.

Resolving patch:
diff --git a/garage/experiment/local_tf_runner.py b/garage/experiment/local_tf_runner.py
--- a/garage/experiment/local_tf_runner.py
+++ b/garage/experiment/local_tf_runner.py
@@ -132,11 +132,14 @@ def setup(self, algo, env, sampler_cls=None, sampler_args=None):
     def initialize_tf_vars(self):
         """Initialize all uninitialized variables in session."""
         with tf.name_scope("initialize_tf_vars"):
+            uninited_set = [
+                e.decode()
+                for e in self.sess.run(tf.report_uninitialized_variables())
+            ]
             self.sess.run(
                 tf.variables_initializer([
                     v for v in tf.global_variables()
-                    if v.name.split(':')[0] in str(
-                        self.sess.run(tf.report_uninitialized_variables()))
+                    if v.name.split(':')[0] in uninited_set
                 ]))
 
     def start_worker(self):


Test patch:
Repository: rlworkgroup/garage

Issue:
LocalRunner closes tf sessions it does not own
`garage.experiment.local_tf_runner.LocalRunner` will close its tf session in `__exit__`. However, the session may not have been created by LocalRunner and may be managed by some other entity. Closing externally-owned sessions can lead to unexpected behavior or failures.

Example:
```
with tf.Session() as sess:
  with LocalRunner(sess=sess) as runner:
    # Run an experiment
```
Code will fail with error:
`AttributeError: 'NoneType' object has no attribute '__exit__'`


Discussion:

Resolving patch:
diff --git a/garage/experiment/local_tf_runner.py b/garage/experiment/local_tf_runner.py
--- a/garage/experiment/local_tf_runner.py
+++ b/garage/experiment/local_tf_runner.py
@@ -67,6 +67,7 @@ def __init__(self, sess=None, max_cpus=1):
             from garage.sampler import singleton_pool
             singleton_pool.initialize(max_cpus)
         self.sess = sess or tf.Session()
+        self.sess_entered = False
         self.has_setup = False
         self.plot = False
 
@@ -79,12 +80,14 @@ def __enter__(self):
         """
         if tf.get_default_session() is not self.sess:
             self.sess.__enter__()
+            self.sess_entered = True
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
         """Leave session."""
-        if tf.get_default_session() is self.sess:
+        if tf.get_default_session() is self.sess and self.sess_entered:
             self.sess.__exit__(exc_type, exc_val, exc_tb)
+            self.sess_entered = False
 
     def setup(self, algo, env, sampler_cls=None, sampler_args=None):
         """Set up runner for algorithm and environment.


Test patch:
diff --git a/tests/garage/experiment/test_local_tf_runner.py b/tests/garage/experiment/test_local_tf_runner.py
--- a/tests/garage/experiment/test_local_tf_runner.py
+++ b/tests/garage/experiment/test_local_tf_runner.py
@@ -105,3 +105,10 @@ def test_train(self):
 
             runner.setup(algo, env)
             runner.train(n_epochs=1, batch_size=100)
+
+    def test_external_sess(self):
+        with tf.Session() as sess:
+            with LocalRunner(sess=sess):
+                pass
+            # sess should still be the default session here.
+            tf.no_op().run()
Repository: rlworkgroup/garage

Issue:
FireReset is firing warnings in the CI
from recent tests runs
```sh
UserWarning: WARN: <class 'garage.envs.wrappers.fire_reset.FireReset'> doesn't implement 'step' method, which is required for wrappers derived directly from Wrapper. Deprecated default implementation is used.
```


Discussion:

Resolving patch:
diff --git a/garage/envs/wrappers/clip_reward.py b/garage/envs/wrappers/clip_reward.py
--- a/garage/envs/wrappers/clip_reward.py
+++ b/garage/envs/wrappers/clip_reward.py
@@ -10,3 +10,7 @@ def step(self, ac):
         """gym.Env step function."""
         obs, reward, done, info = self.env.step(ac)
         return obs, np.sign(reward), done, info
+
+    def reset(self):
+        """gym.Env reset."""
+        return self.env.reset()
diff --git a/garage/envs/wrappers/fire_reset.py b/garage/envs/wrappers/fire_reset.py
--- a/garage/envs/wrappers/fire_reset.py
+++ b/garage/envs/wrappers/fire_reset.py
@@ -15,9 +15,9 @@ class FireReset(gym.Wrapper):
     def __init__(self, env):
         super().__init__(env)
         assert env.unwrapped.get_action_meanings()[1] == 'FIRE', (
-            "Only use fire reset wrapper for suitable environment!")
+            'Only use fire reset wrapper for suitable environment!')
         assert len(env.unwrapped.get_action_meanings()) >= 3, (
-            "Only use fire reset wrapper for suitable environment!")
+            'Only use fire reset wrapper for suitable environment!')
 
     def reset(self, **kwargs):
         """gym.Env reset function."""
@@ -26,3 +26,7 @@ def reset(self, **kwargs):
         if done:
             obs = self.env.reset(**kwargs)
         return obs
+
+    def step(self, action):
+        """gym.Env step function."""
+        return self.env.step(action)
diff --git a/garage/envs/wrappers/noop.py b/garage/envs/wrappers/noop.py
--- a/garage/envs/wrappers/noop.py
+++ b/garage/envs/wrappers/noop.py
@@ -19,7 +19,7 @@ def __init__(self, env, noop_max=30):
         super().__init__(env)
         self._noop_max = noop_max
         self._noop_action = 0
-        assert noop_max > 0, "noop_max should be larger than 0!"
+        assert noop_max > 0, 'noop_max should be larger than 0!'
         assert env.unwrapped.get_action_meanings()[0] == 'NOOP', (
             "No-op should be the 0-th action but it's not in {}!".format(env))
 
@@ -28,7 +28,11 @@ def reset(self, **kwargs):
         obs = self.env.reset(**kwargs)
         noops = np.random.randint(1, self._noop_max + 1)
         for _ in range(noops):
-            obs, _, done, _ = self.env.step(self._noop_action)
+            obs, _, done, _ = self.step(self._noop_action)
             if done:
                 obs = self.env.reset(**kwargs)
         return obs
+
+    def step(self, action):
+        """gym.Env step function."""
+        return self.env.step(action)


Test patch:
Repository: rlworkgroup/garage

Issue:
sim_policy not working
Hi, 
I just found that sim_policy.py cannot work. 
data that read from "params.pkl" does not include the key of "policy"


Discussion:
@zequnyu @naeioi can you take a look?
@xht033 True. Thanks for reporting! This is because starting from https://github.com/rlworkgroup/garage/commit/3cd1718eece4f3c1cbae6f63cc409ee1e79720c1 we save `algo`  instead of `policy`. If you are eager for a quick fix, try replacing `data['policy']` by `data['algo'].policy`. Or wait for my PR expected to file tommorow.

Resolving patch:
diff --git a/examples/sim_policy.py b/examples/sim_policy.py
--- a/examples/sim_policy.py
+++ b/examples/sim_policy.py
@@ -8,7 +8,7 @@
 from garage.misc.console import query_yes_no
 from garage.sampler.utils import rollout
 
-if __name__ == "__main__":
+if __name__ == '__main__':
 
     parser = argparse.ArgumentParser()
     parser.add_argument('file', type=str, help='path to the snapshot file')
@@ -26,7 +26,7 @@
     #     [rest of the code]
     with tf.Session() as sess:
         data = joblib.load(args.file)
-        policy = data['policy']
+        policy = data['algo'].policy
         env = data['env']
         while True:
             path = rollout(


Test patch:
Repository: rlworkgroup/garage

Issue:
Add Intel-optimized version of the package



Discussion:
This might require building from source because Intel doesn't seem in a hurry to keep their wheels updated.
FYI i tried this on my machine and it was actually much slower than vanilla tensorflow-cpu, but I probably didn't install it correctly.
See also https://github.com/rlworkgroup/garage/issues/220
* intel-numpy
* intel-scipy
* intel-optimized TF
* intel-optimized PyTorch?

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -34,6 +34,9 @@
 extras = {}
 extras['all'] = list(set(sum(extras.values(), [])))
 
+# Intel dependencies not included in all
+extras['intel'] = ['intel-tensorflow<1.13,>=1.12.0']
+
 # Development dependencies (*not* included in "all")
 extras['dev'] = [
     # Please keep alphabetized


Test patch:
Repository: rlworkgroup/garage

Issue:
Nightly builds are failing
https://travis-ci.com/rlworkgroup/garage/jobs/213465246

I think it may have been a API change in pyglet. we may need to pin that dep.


Discussion:
Is this maybe connected:
```
Traceback (most recent call last):
  File "run_scripts/2019_07_06_22_59_33_0000/run.py", line 15, in <module>
    from garage.envs import normalize
  File "/venvs/rl_env/lib/python3.6/site-packages/garage/envs/__init__.py", line 1, in <module>
    from garage.envs.base import GarageEnv
  File "/venvs/rl_env/lib/python3.6/site-packages/garage/envs/base.py", line 7, in <module>
    from gym.envs.classic_control.rendering import SimpleImageViewer
  File "/venvs/rl_env/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 27, in <module>
    from pyglet.gl import *
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 237, in <module>
    import pyglet.window
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/window/__init__.py", line 1868, in <module>
    gl._create_shadow_window()
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 209, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 171, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/window/__init__.py", line 574, in __init__
    display = pyglet.canvas.get_display()
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/canvas/__init__.py", line 96, in get_display
    return Display()
  File "/venvs/rl_env/lib/python3.6/site-packages/pyglet/canvas/xlib.py", line 120, in __init__
    raise NoSuchDisplayException('Cannot connect to "%s"' % name)
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"
```
I'm trying to run scripts on cluster without display.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,6 +21,10 @@
     'mujoco-py<2.1,>=2.0',
     'numpy==1.14.5',
     'psutil',
+    # Pyglet 1.4.0 introduces some api change which breaks some
+    # gym environments
+    # See: https://github.com/openai/gym/issues/1588
+    'pyglet<1.4.0,>=1.3.0',
     'pyprind',
     'python-dateutil',
     'torch==1.1.0',


Test patch:
Repository: TencentBlueKing/bk-user

Issue:
改进部署 Helm Chart，降低部署门槛
- 默认禁用权限中心配置，并添加手动注册权限中心的文档指引
- `ingress` 资源修改成 `networking/v1` 版本
- ~~修复当 `mariadb` 禁用时，`envFrom` 挂载失败问题~~
- 增加 `redis` 内建存储，作为 `Celery Broker`
- 修正若干文档 & 注释指引
- 增加初始化管理员账号密码修改指引
- 支持全局配置镜像 `registry`
- `service` 名字添加前缀，和其他 Chart 区分


Discussion:

Resolving patch:
diff --git a/src/api/bkuser_core/config/common/platform.py b/src/api/bkuser_core/config/common/platform.py
--- a/src/api/bkuser_core/config/common/platform.py
+++ b/src/api/bkuser_core/config/common/platform.py
@@ -16,8 +16,8 @@
 # ==============================================================================
 # 应用基本信息配置
 # ==============================================================================
-APP_ID = env("APP_ID")
-APP_TOKEN = env("APP_TOKEN")
+APP_ID = env("BK_APP_CODE")
+APP_TOKEN = env("BK_APP_SECRET")
 
 # ==============================================================================
 # 蓝鲸平台相关配置
diff --git a/src/saas/bkuser_shell/config/common/platform.py b/src/saas/bkuser_shell/config/common/platform.py
--- a/src/saas/bkuser_shell/config/common/platform.py
+++ b/src/saas/bkuser_shell/config/common/platform.py
@@ -14,8 +14,8 @@
 # 应用基本信息配置 (请按照说明修改)
 # ==============================================================================
 # 在蓝鲸智云开发者中心 -> 点击应用ID -> 基本信息 中获取 APP_ID 和 APP_TOKEN 的值
-APP_ID = env("APP_ID", default="bk_user_manage")
-APP_TOKEN = env("APP_TOKEN", default="04631675-6ddf-4f8f-a199-c397cb19f4f8")
+APP_ID = env("BK_APP_CODE")
+APP_TOKEN = env("BK_APP_SECRET")
 # 蓝鲸智云开发者中心的域名，形如：http://paas.bking.com
 BK_PAAS_HOST = env("BK_PAAS_HOST")
 BK_PAAS_INNER_HOST = env("BK_PAAS_INNER_HOST", default=BK_PAAS_HOST)


Test patch:
Repository: TencentBlueKing/bk-user

Issue:
修复 SaaS 目录配置页面出现白屏，无法拉取到正确配置的问题
填写完基本信息后，会出现配置白屏

![image](https://user-images.githubusercontent.com/4225292/130004154-aca12be1-0187-4938-87f4-581b2fba3a8d.png)

实际上的原因是我们的 `views` 装饰器存在一个 bug，当用户传入 `serializer` 对象时，会使得上一次请求的数据残留
修复 SaaS 目录配置页面出现白屏，无法拉取到正确配置的问题
填写完基本信息后，会出现配置白屏

![image](https://user-images.githubusercontent.com/4225292/130004154-aca12be1-0187-4938-87f4-581b2fba3a8d.png)

实际上的原因是我们的 `views` 装饰器存在一个 bug，当用户传入 `serializer` 对象时，会使得上一次请求的数据残留


Discussion:

Resolving patch:
diff --git a/src/bkuser_global/drf_crown/crown.py b/src/bkuser_global/drf_crown/crown.py
--- a/src/bkuser_global/drf_crown/crown.py
+++ b/src/bkuser_global/drf_crown/crown.py
@@ -138,6 +138,11 @@ def get_response(self, data, out_params: dict) -> Any:
             return data
 
         if isinstance(self.out, BaseSerializer):
+            # 由于传入的是全局对象，会残留上一次请求的结果
+            # 这里需要手动清理一下
+            if hasattr(self.out, "_data"):
+                delattr(self.out, "_data")
+
             self.out.instance = data
             _data = self.out.data
         elif issubclass(self.out, BaseSerializer):
@@ -178,7 +183,7 @@ def inject_serializer(
     :param query_in: input serializer (query)
     :param out: output serializer
     :param config: initial info of Config
-    :param swagger_params: pass to swagger_auto_schema of drf-yasg
+    :param swagger_kwargs: pass to swagger_auto_schema of drf-yasg
     """
 
     def decorator_serializer_inject(func):
diff --git a/src/saas/bkuser_shell/config_center/views.py b/src/saas/bkuser_shell/config_center/views.py
--- a/src/saas/bkuser_shell/config_center/views.py
+++ b/src/saas/bkuser_shell/config_center/views.py
@@ -201,7 +201,7 @@ def list_defaults(self, request, validated_data):
         return setting_metas
 
     @inject_serializer(
-        query_in=serializers.UpdateNamespaceSettingSerializer(),
+        query_in=serializers.UpdateNamespaceSettingSerializer(many=True),
         out=serializers.SettingSerializer(many=True),
         tags=["config_center"],
     )
@@ -232,7 +232,9 @@ def update(self, request, category_id, namespace_name, validated_data):
         return result
 
     @inject_serializer(
-        body_in=serializers.SettingSerializer, out=serializers.SettingSerializer(many=True), tags=["config_center"]
+        body_in=serializers.SettingSerializer(many=True),
+        out=serializers.SettingSerializer(many=True),
+        tags=["config_center"],
     )
     def create(self, request, category_id, namespace_name, validated_data):
         """批量创建一个 namespace 下的配置"""


Test patch: