prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  collection.convert
  Would like to support syntax `collection.convert(unit)`.
  
  Would convert all contained data objects recursively.
  
  </issue>
  <code>
  [start of WrightTools/collection/_collection.py]
  1 """Collection."""
  2 
  3 
  4 # --- import --------------------------------------------------------------------------------------
  5 
  6 
  7 import numpy as np
  8 
  9 from .. import data as wt_data
  10 from .. import exceptions as wt_exceptions
  11 from .._group import Group
  12 
  13 
  14 # --- define --------------------------------------------------------------------------------------
  15 
  16 
  17 __all__ = ["Collection"]
  18 
  19 
  20 # --- classes -------------------------------------------------------------------------------------
  21 
  22 
  23 class Collection(Group):
  24     """Nestable Collection of Data objects."""
  25 
  26     class_name = "Collection"
  27 
  28     def __iter__(self):
  29         self.__n = 0
  30         return self
  31 
  32     def __len__(self):
  33         return len(self.item_names)
  34 
  35     def __next__(self):
  36         if self.__n < len(self):
  37             out = self.item_names[self.__n]
  38             self.__n += 1
  39         else:
  40             raise StopIteration
  41         return out
  42 
  43     def __repr__(self):
  44         return "<WrightTools.Collection '{0}' {1} at {2}>".format(
  45             self.natural_name, self.item_names, "::".join([self.filepath, self.name])
  46         )
  47 
  48     def __getitem__(self, key):
  49         if isinstance(key, int):
  50             key = self.item_names[key]
  51         if key == "":
  52             return None
  53         return super().__getitem__(key)
  54 
  55     def __setitem__(self, key, value):
  56         raise NotImplementedError
  57 
  58     @property
  59     def _leaf(self):
  60         return self.natural_name
  61 
  62     def _print_branch(self, prefix, depth, verbose):
  63         for i, name in enumerate(self.item_names):
  64             item = self[name]
  65             if i + 1 == len(self.item_names):
  66                 s = prefix + "└── {0}: {1}".format(i, item._leaf)
  67                 p = prefix + "    "
  68             else:
  69                 s = prefix + "├── {0}: {1}".format(i, item._leaf)
  70                 p = prefix + "│   "
  71             print(s)
  72             if depth > 1 and hasattr(item, "_print_branch"):
  73                 item._print_branch(p, depth=depth - 1, verbose=verbose)
  74 
  75     def create_collection(self, name="collection", position=None, **kwargs):
  76         """Create a new child colleciton.
  77 
  78         Parameters
  79         ----------
  80         name : string
  81             Unique identifier.
  82         position : integer (optional)
  83             Location to insert. Default is None (append).
  84         kwargs
  85             Additional arguments to child collection instantiation.
  86 
  87         Returns
  88         -------
  89         WrightTools Collection
  90             New child.
  91         """
  92         if name in self.item_names:
  93             wt_exceptions.ObjectExistsWarning.warn(name)
  94             return self[name]
  95         collection = Collection(
  96             filepath=self.filepath, parent=self.name, name=name, edit_local=True, **kwargs
  97         )
  98         if position is not None:
  99             self.attrs["item_names"] = np.insert(
  100                 self.attrs["item_names"][:-1], position, collection.natural_name.encode()
  101             )
  102         setattr(self, name, collection)
  103         return collection
  104 
  105     def create_data(self, name="data", position=None, **kwargs):
  106         """Create a new child data.
  107 
  108         Parameters
  109         ----------
  110         name : string
  111             Unique identifier.
  112         position : integer (optional)
  113             Location to insert. Default is None (append).
  114         kwargs
  115             Additional arguments to child data instantiation.
  116 
  117         Returns
  118         -------
  119         WrightTools Data
  120             New child.
  121         """
  122         if name in self.item_names:
  123             wt_exceptions.ObjectExistsWarning.warn(name)
  124             return self[name]
  125 
  126         if name == "":
  127             data = None
  128             natural_name = "".encode()
  129         else:
  130             data = wt_data.Data(
  131                 filepath=self.filepath, parent=self.name, name=name, edit_local=True, **kwargs
  132             )
  133             natural_name = data.natural_name.encode()
  134         if position is not None:
  135             self.attrs["item_names"] = np.insert(
  136                 self.attrs["item_names"][:-1], position, natural_name
  137             )
  138         setattr(self, name, data)
  139         return data
  140 
  141     def index(self):
  142         """Index."""
  143         raise NotImplementedError
  144 
  145     def print_tree(self, depth=9, *, verbose=False):
  146         """Print a ascii-formatted tree representation of the collection contents.
  147 
  148         Parameters
  149         ----------
  150         depth : integer (optional)
  151             Number of layers to include in the tree. Default is 9.
  152         verbose : boolean (optional)
  153             Toggle inclusion of extra information. Default is True.
  154         """
  155         print("{0} ({1})".format(self.natural_name, self.filepath))
  156         self._print_branch("", depth=depth, verbose=verbose)
  157 
  158     def flush(self):
  159         """Ensure contents are written to file."""
  160         for name in self.item_names:
  161             item = self[name]
  162             item.flush()
  163         self.file.flush()
  164
  [end of WrightTools/collection/_collection.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/WrightTools/collection/_collection.py b/WrightTools/collection/_collection.py
  --- a/WrightTools/collection/_collection.py
  +++ b/WrightTools/collection/_collection.py
  @@ -102,6 +102,18 @@
           setattr(self, name, collection)
           return collection
   
  +    def convert(self, units, convert_variables=False, verbose=True):
  +        """Convert units of a collection.
  +        Parameters
  +        ----------
  +        units: string
  +            Units to convert to.
  +        """
  +
  +        for name in self.item_names:
  +            item = self[name]
  +            item.convert(units, convert_variables=convert_variables, verbose=verbose)
  +
       def create_data(self, name="data", position=None, **kwargs):
           """Create a new child data.
  
verification_info: {"golden_diff": "diff --git a/WrightTools/collection/_collection.py b/WrightTools/collection/_collection.py\n--- a/WrightTools/collection/_collection.py\n+++ b/WrightTools/collection/_collection.py\n@@ -102,6 +102,18 @@\n         setattr(self, name, collection)\n         return collection\n \n+    def convert(self, units, convert_variables=False, verbose=True):\n+        \"\"\"Convert units of a collection.\n+        Parameters\n+        ----------\n+        units: string\n+            Units to convert to.\n+        \"\"\"\n+\n+        for name in self.item_names:\n+            item = self[name]\n+            item.convert(units, convert_variables=convert_variables, verbose=verbose)\n+\n     def create_data(self, name=\"data\", position=None, **kwargs):\n         \"\"\"Create a new child data.\n", "issue": "collection.convert\nWould like to support syntax `collection.convert(unit)`.\r\n\r\nWould convert all contained data objects recursively.\n", "before_files": [{"content": "\"\"\"Collection.\"\"\"\n\n\n# --- import --------------------------------------------------------------------------------------\n\n\nimport numpy as np\n\nfrom .. import data as wt_data\nfrom .. import exceptions as wt_exceptions\nfrom .._group import Group\n\n\n# --- define --------------------------------------------------------------------------------------\n\n\n__all__ = [\"Collection\"]\n\n\n# --- classes -------------------------------------------------------------------------------------\n\n\nclass Collection(Group):\n    \"\"\"Nestable Collection of Data objects.\"\"\"\n\n    class_name = \"Collection\"\n\n    def __iter__(self):\n        self.__n = 0\n        return self\n\n    def __len__(self):\n        return len(self.item_names)\n\n    def __next__(self):\n        if self.__n < len(self):\n            out = self.item_names[self.__n]\n            self.__n += 1\n        else:\n            raise StopIteration\n        return out\n\n    def __repr__(self):\n        return \"<WrightTools.Collection '{0}' {1} at {2}>\".format(\n            self.natural_name, self.item_names, \"::\".join([self.filepath, self.name])\n        )\n\n    def __getitem__(self, key):\n        if isinstance(key, int):\n            key = self.item_names[key]\n        if key == \"\":\n            return None\n        return super().__getitem__(key)\n\n    def __setitem__(self, key, value):\n        raise NotImplementedError\n\n    @property\n    def _leaf(self):\n        return self.natural_name\n\n    def _print_branch(self, prefix, depth, verbose):\n        for i, name in enumerate(self.item_names):\n            item = self[name]\n            if i + 1 == len(self.item_names):\n                s = prefix + \"\u2514\u2500\u2500 {0}: {1}\".format(i, item._leaf)\n                p = prefix + \"    \"\n            else:\n                s = prefix + \"\u251c\u2500\u2500 {0}: {1}\".format(i, item._leaf)\n                p = prefix + \"\u2502   \"\n            print(s)\n            if depth > 1 and hasattr(item, \"_print_branch\"):\n                item._print_branch(p, depth=depth - 1, verbose=verbose)\n\n    def create_collection(self, name=\"collection\", position=None, **kwargs):\n        \"\"\"Create a new child colleciton.\n\n        Parameters\n        ----------\n        name : string\n            Unique identifier.\n        position : integer (optional)\n            Location to insert. Default is None (append).\n        kwargs\n            Additional arguments to child collection instantiation.\n\n        Returns\n        -------\n        WrightTools Collection\n            New child.\n        \"\"\"\n        if name in self.item_names:\n            wt_exceptions.ObjectExistsWarning.warn(name)\n            return self[name]\n        collection = Collection(\n            filepath=self.filepath, parent=self.name, name=name, edit_local=True, **kwargs\n        )\n        if position is not None:\n            self.attrs[\"item_names\"] = np.insert(\n                self.attrs[\"item_names\"][:-1], position, collection.natural_name.encode()\n            )\n        setattr(self, name, collection)\n        return collection\n\n    def create_data(self, name=\"data\", position=None, **kwargs):\n        \"\"\"Create a new child data.\n\n        Parameters\n        ----------\n        name : string\n            Unique identifier.\n        position : integer (optional)\n            Location to insert. Default is None (append).\n        kwargs\n            Additional arguments to child data instantiation.\n\n        Returns\n        -------\n        WrightTools Data\n            New child.\n        \"\"\"\n        if name in self.item_names:\n            wt_exceptions.ObjectExistsWarning.warn(name)\n            return self[name]\n\n        if name == \"\":\n            data = None\n            natural_name = \"\".encode()\n        else:\n            data = wt_data.Data(\n                filepath=self.filepath, parent=self.name, name=name, edit_local=True, **kwargs\n            )\n            natural_name = data.natural_name.encode()\n        if position is not None:\n            self.attrs[\"item_names\"] = np.insert(\n                self.attrs[\"item_names\"][:-1], position, natural_name\n            )\n        setattr(self, name, data)\n        return data\n\n    def index(self):\n        \"\"\"Index.\"\"\"\n        raise NotImplementedError\n\n    def print_tree(self, depth=9, *, verbose=False):\n        \"\"\"Print a ascii-formatted tree representation of the collection contents.\n\n        Parameters\n        ----------\n        depth : integer (optional)\n            Number of layers to include in the tree. Default is 9.\n        verbose : boolean (optional)\n            Toggle inclusion of extra information. Default is True.\n        \"\"\"\n        print(\"{0} ({1})\".format(self.natural_name, self.filepath))\n        self._print_branch(\"\", depth=depth, verbose=verbose)\n\n    def flush(self):\n        \"\"\"Ensure contents are written to file.\"\"\"\n        for name in self.item_names:\n            item = self[name]\n            item.flush()\n        self.file.flush()\n", "path": "WrightTools/collection/_collection.py"}]}