We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong behavior of SerialIterator if dataset is numpy array.
In `serial_iterator.py` lines [66](https://github.com/pfnet/chainer/blob/master/chainer/iterators/serial_iterator.py#L66) and [68](https://github.com/pfnet/chainer/blob/master/chainer/iterators/serial_iterator.py#L68) contain `+=` to extend lists.

Unfortunately, this does not crash for `numpy` arrays but produces undesired behavior. The dataset itself gets modified (see for `6` in the second example):

```
import numpy as np
from chainer.iterators.serial_iterator import SerialIterator

dataset = [1, 2, 3, 4, 5]
it = SerialIterator(dataset, batch_size=2, shuffle=False)

for _ in range(6):
    example = it.next()
    print(example)
```

```
[1, 2]
[3, 4]
[5, 1]
[2, 3]
[4, 5]
[1, 2]
```

```
dataset = np.asarray([1, 2, 3, 4, 5])
it = SerialIterator(dataset, batch_size=2, shuffle=False)

for _ in range(6):
    example = it.next()
    print(example)
```

```
[1 2]
[3 4]
[6]
[2 3]
[4 6]
[1 2]
```

When the two lines get changed to
```
batch.extend(list(self.dataset[:rest]))
```

and
```
batch.extend([self.dataset[index] for index in self._order[:rest]])
```

a useful error is raised.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainer/iterators/serial_iterator.py`
Content:
```
1 from __future__ import division
2 
3 import numpy
4 
5 from chainer.dataset import iterator
6 
7 
8 class SerialIterator(iterator.Iterator):
9 
10     """Dataset iterator that serially reads the examples.
11 
12     This is a simple implementation of :class:`~chainer.dataset.Iterator`
13     that just visits each example in either the order of indexes or a shuffled
14     order.
15 
16     To avoid unintentional performance degradation, the ``shuffle`` option is
17     set to ``True`` by default. For validation, it is better to set it to
18     ``False`` when the underlying dataset supports fast slicing. If the
19     order of examples has an important meaning and the updater depends on the
20     original order, this option should be set to ``False``.
21 
22     Args:
23         dataset: Dataset to iterate.
24         batch_size (int): Number of examples within each batch.
25         repeat (bool): If ``True``, it infinitely loops over the dataset.
26             Otherwise, it stops iteration at the end of the first epoch.
27         shuffle (bool): If ``True``, the order of examples is shuffled at the
28             beginning of each epoch. Otherwise, examples are extracted in the
29             order of indexes.
30 
31     """
32 
33     def __init__(self, dataset, batch_size, repeat=True, shuffle=True):
34         self.dataset = dataset
35         self.batch_size = batch_size
36         self._repeat = repeat
37         if shuffle:
38             self._order = numpy.random.permutation(len(dataset))
39         else:
40             self._order = None
41 
42         self.current_position = 0
43         self.epoch = 0
44         self.is_new_epoch = False
45 
46     def __next__(self):
47         if not self._repeat and self.epoch > 0:
48             raise StopIteration
49 
50         i = self.current_position
51         i_end = i + self.batch_size
52         N = len(self.dataset)
53 
54         if self._order is None:
55             batch = self.dataset[i:i_end]
56         else:
57             batch = [self.dataset[index] for index in self._order[i:i_end]]
58 
59         if i_end >= N:
60             if self._repeat:
61                 rest = i_end - N
62                 if self._order is not None:
63                     numpy.random.shuffle(self._order)
64                 if rest > 0:
65                     if self._order is None:
66                         batch += list(self.dataset[:rest])
67                     else:
68                         batch += [self.dataset[index]
69                                   for index in self._order[:rest]]
70                 self.current_position = rest
71             else:
72                 self.current_position = N
73 
74             self.epoch += 1
75             self.is_new_epoch = True
76         else:
77             self.is_new_epoch = False
78             self.current_position = i_end
79 
80         return batch
81 
82     next = __next__
83 
84     @property
85     def epoch_detail(self):
86         return self.epoch + self.current_position / len(self.dataset)
87 
88     def serialize(self, serializer):
89         self.current_position = serializer('current_position',
90                                            self.current_position)
91         self.epoch = serializer('epoch', self.epoch)
92         self.is_new_epoch = serializer('is_new_epoch', self.is_new_epoch)
93         if self._order is not None:
94             serializer('_order', self._order)
95
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chainer/iterators/serial_iterator.py b/chainer/iterators/serial_iterator.py
--- a/chainer/iterators/serial_iterator.py
+++ b/chainer/iterators/serial_iterator.py
@@ -63,10 +63,10 @@
                     numpy.random.shuffle(self._order)
                 if rest > 0:
                     if self._order is None:
-                        batch += list(self.dataset[:rest])
+                        batch.extend(self.dataset[:rest])
                     else:
-                        batch += [self.dataset[index]
-                                  for index in self._order[:rest]]
+                        batch.extend([self.dataset[index]
+                                      for index in self._order[:rest]])
                 self.current_position = rest
             else:
                 self.current_position = N

{"golden_diff": "diff --git a/chainer/iterators/serial_iterator.py b/chainer/iterators/serial_iterator.py\n--- a/chainer/iterators/serial_iterator.py\n+++ b/chainer/iterators/serial_iterator.py\n@@ -63,10 +63,10 @@\n                     numpy.random.shuffle(self._order)\n                 if rest > 0:\n                     if self._order is None:\n-                        batch += list(self.dataset[:rest])\n+                        batch.extend(self.dataset[:rest])\n                     else:\n-                        batch += [self.dataset[index]\n-                                  for index in self._order[:rest]]\n+                        batch.extend([self.dataset[index]\n+                                      for index in self._order[:rest]])\n                 self.current_position = rest\n             else:\n                 self.current_position = N\n", "issue": "Wrong behavior of SerialIterator if dataset is numpy array.\nIn `serial_iterator.py` lines [66](https://github.com/pfnet/chainer/blob/master/chainer/iterators/serial_iterator.py#L66) and [68](https://github.com/pfnet/chainer/blob/master/chainer/iterators/serial_iterator.py#L68) contain `+=` to extend lists.\r\n\r\nUnfortunately, this does not crash for `numpy` arrays but produces undesired behavior. The dataset itself gets modified (see for `6` in the second example):\r\n\r\n```\r\nimport numpy as np\r\nfrom chainer.iterators.serial_iterator import SerialIterator\r\n\r\ndataset = [1, 2, 3, 4, 5]\r\nit = SerialIterator(dataset, batch_size=2, shuffle=False)\r\n\r\nfor _ in range(6):\r\n    example = it.next()\r\n    print(example)\r\n```\r\n\r\n```\r\n[1, 2]\r\n[3, 4]\r\n[5, 1]\r\n[2, 3]\r\n[4, 5]\r\n[1, 2]\r\n```\r\n\r\n```\r\ndataset = np.asarray([1, 2, 3, 4, 5])\r\nit = SerialIterator(dataset, batch_size=2, shuffle=False)\r\n\r\nfor _ in range(6):\r\n    example = it.next()\r\n    print(example)\r\n```\r\n\r\n```\r\n[1 2]\r\n[3 4]\r\n[6]\r\n[2 3]\r\n[4 6]\r\n[1 2]\r\n```\r\n\r\nWhen the two lines get changed to\r\n```\r\nbatch.extend(list(self.dataset[:rest]))\r\n```\r\n\r\nand\r\n```\r\nbatch.extend([self.dataset[index] for index in self._order[:rest]])\r\n```\r\n\r\na useful error is raised.\n", "before_files": [{"content": "from __future__ import division\n\nimport numpy\n\nfrom chainer.dataset import iterator\n\n\nclass SerialIterator(iterator.Iterator):\n\n    \"\"\"Dataset iterator that serially reads the examples.\n\n    This is a simple implementation of :class:`~chainer.dataset.Iterator`\n    that just visits each example in either the order of indexes or a shuffled\n    order.\n\n    To avoid unintentional performance degradation, the ``shuffle`` option is\n    set to ``True`` by default. For validation, it is better to set it to\n    ``False`` when the underlying dataset supports fast slicing. If the\n    order of examples has an important meaning and the updater depends on the\n    original order, this option should be set to ``False``.\n\n    Args:\n        dataset: Dataset to iterate.\n        batch_size (int): Number of examples within each batch.\n        repeat (bool): If ``True``, it infinitely loops over the dataset.\n            Otherwise, it stops iteration at the end of the first epoch.\n        shuffle (bool): If ``True``, the order of examples is shuffled at the\n            beginning of each epoch. Otherwise, examples are extracted in the\n            order of indexes.\n\n    \"\"\"\n\n    def __init__(self, dataset, batch_size, repeat=True, shuffle=True):\n        self.dataset = dataset\n        self.batch_size = batch_size\n        self._repeat = repeat\n        if shuffle:\n            self._order = numpy.random.permutation(len(dataset))\n        else:\n            self._order = None\n\n        self.current_position = 0\n        self.epoch = 0\n        self.is_new_epoch = False\n\n    def __next__(self):\n        if not self._repeat and self.epoch > 0:\n            raise StopIteration\n\n        i = self.current_position\n        i_end = i + self.batch_size\n        N = len(self.dataset)\n\n        if self._order is None:\n            batch = self.dataset[i:i_end]\n        else:\n            batch = [self.dataset[index] for index in self._order[i:i_end]]\n\n        if i_end >= N:\n            if self._repeat:\n                rest = i_end - N\n                if self._order is not None:\n                    numpy.random.shuffle(self._order)\n                if rest > 0:\n                    if self._order is None:\n                        batch += list(self.dataset[:rest])\n                    else:\n                        batch += [self.dataset[index]\n                                  for index in self._order[:rest]]\n                self.current_position = rest\n            else:\n                self.current_position = N\n\n            self.epoch += 1\n            self.is_new_epoch = True\n        else:\n            self.is_new_epoch = False\n            self.current_position = i_end\n\n        return batch\n\n    next = __next__\n\n    @property\n    def epoch_detail(self):\n        return self.epoch + self.current_position / len(self.dataset)\n\n    def serialize(self, serializer):\n        self.current_position = serializer('current_position',\n                                           self.current_position)\n        self.epoch = serializer('epoch', self.epoch)\n        self.is_new_epoch = serializer('is_new_epoch', self.is_new_epoch)\n        if self._order is not None:\n            serializer('_order', self._order)\n", "path": "chainer/iterators/serial_iterator.py"}], "after_files": [{"content": "from __future__ import division\n\nimport numpy\n\nfrom chainer.dataset import iterator\n\n\nclass SerialIterator(iterator.Iterator):\n\n    \"\"\"Dataset iterator that serially reads the examples.\n\n    This is a simple implementation of :class:`~chainer.dataset.Iterator`\n    that just visits each example in either the order of indexes or a shuffled\n    order.\n\n    To avoid unintentional performance degradation, the ``shuffle`` option is\n    set to ``True`` by default. For validation, it is better to set it to\n    ``False`` when the underlying dataset supports fast slicing. If the\n    order of examples has an important meaning and the updater depends on the\n    original order, this option should be set to ``False``.\n\n    Args:\n        dataset: Dataset to iterate.\n        batch_size (int): Number of examples within each batch.\n        repeat (bool): If ``True``, it infinitely loops over the dataset.\n            Otherwise, it stops iteration at the end of the first epoch.\n        shuffle (bool): If ``True``, the order of examples is shuffled at the\n            beginning of each epoch. Otherwise, examples are extracted in the\n            order of indexes.\n\n    \"\"\"\n\n    def __init__(self, dataset, batch_size, repeat=True, shuffle=True):\n        self.dataset = dataset\n        self.batch_size = batch_size\n        self._repeat = repeat\n        if shuffle:\n            self._order = numpy.random.permutation(len(dataset))\n        else:\n            self._order = None\n\n        self.current_position = 0\n        self.epoch = 0\n        self.is_new_epoch = False\n\n    def __next__(self):\n        if not self._repeat and self.epoch > 0:\n            raise StopIteration\n\n        i = self.current_position\n        i_end = i + self.batch_size\n        N = len(self.dataset)\n\n        if self._order is None:\n            batch = self.dataset[i:i_end]\n        else:\n            batch = [self.dataset[index] for index in self._order[i:i_end]]\n\n        if i_end >= N:\n            if self._repeat:\n                rest = i_end - N\n                if self._order is not None:\n                    numpy.random.shuffle(self._order)\n                if rest > 0:\n                    if self._order is None:\n                        batch.extend(self.dataset[:rest])\n                    else:\n                        batch.extend([self.dataset[index]\n                                      for index in self._order[:rest]])\n                self.current_position = rest\n            else:\n                self.current_position = N\n\n            self.epoch += 1\n            self.is_new_epoch = True\n        else:\n            self.is_new_epoch = False\n            self.current_position = i_end\n\n        return batch\n\n    next = __next__\n\n    @property\n    def epoch_detail(self):\n        return self.epoch + self.current_position / len(self.dataset)\n\n    def serialize(self, serializer):\n        self.current_position = serializer('current_position',\n                                           self.current_position)\n        self.epoch = serializer('epoch', self.epoch)\n        self.is_new_epoch = serializer('is_new_epoch', self.is_new_epoch)\n        if self._order is not None:\n            serializer('_order', self._order)\n", "path": "chainer/iterators/serial_iterator.py"}]}