prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  HDF5Exporter: throws error when curves aren't the same length
  When trying to save data from a graph as an hdf5 file, the HDF5Exporter throws and error when you have multiple curves with differing lengths. This looks to be because the numpy.array(data).astype('double') can't handle lists with different lengths. Below is a traceback from the error. This occurs when trying to save data from the "Multiple curves" graph in the "Basic Plotting" example.
  
  ````
  Traceback (most recent call last):
    File "/home/jchrist/PycharmProjects/lib/python3.5/site-packages/pyqtgraph/exporters/Exporter.py", line 77, in fileSaveFinished
      self.export(fileName=fileName, **self.fileDialog.opts)
    File "/home/jchrist/PycharmProjects/lib/python3.5/site-packages/pyqtgraph/exporters/HDF5Exporter.py", line 55, in export
      fdata = numpy.array(data).astype('double')
  ValueError: setting an array element with a sequence.
  ````
  
  </issue>
  <code>
  [start of pyqtgraph/exporters/HDF5Exporter.py]
  1 from ..Qt import QtGui, QtCore
  2 from .Exporter import Exporter
  3 from ..parametertree import Parameter
  4 from .. import PlotItem
  5 
  6 import numpy 
  7 try:
  8     import h5py
  9     HAVE_HDF5 = True
  10 except ImportError:
  11     HAVE_HDF5 = False
  12     
  13 __all__ = ['HDF5Exporter']
  14 
  15     
  16 class HDF5Exporter(Exporter):
  17     Name = "HDF5 Export: plot (x,y)"
  18     windows = []
  19     allowCopy = False
  20 
  21     def __init__(self, item):
  22         Exporter.__init__(self, item)
  23         self.params = Parameter(name='params', type='group', children=[
  24             {'name': 'Name', 'type': 'str', 'value': 'Export',},
  25             {'name': 'columnMode', 'type': 'list', 'values': ['(x,y) per plot', '(x,y,y,y) for all plots']},
  26         ])
  27         
  28     def parameters(self):
  29         return self.params
  30     
  31     def export(self, fileName=None):
  32         if not HAVE_HDF5:
  33             raise RuntimeError("This exporter requires the h5py package, "
  34                                "but it was not importable.")
  35         
  36         if not isinstance(self.item, PlotItem):
  37             raise Exception("Must have a PlotItem selected for HDF5 export.")
  38         
  39         if fileName is None:
  40             self.fileSaveDialog(filter=["*.h5", "*.hdf", "*.hd5"])
  41             return
  42         dsname = self.params['Name']
  43         fd = h5py.File(fileName, 'a') # forces append to file... 'w' doesn't seem to "delete/overwrite"
  44         data = []
  45 
  46         appendAllX = self.params['columnMode'] == '(x,y) per plot'
  47         #print dir(self.item.curves[0])
  48         tlen = 0
  49         for i, c in enumerate(self.item.curves):
  50             d = c.getData()
  51             if i > 0 and len(d[0]) != tlen:
  52                 raise ValueError ("HDF5 Export requires all curves in plot to have same length")
  53             if appendAllX or i == 0:
  54                 data.append(d[0])
  55                 tlen = len(d[0])
  56             data.append(d[1])
  57 
  58 
  59         fdata = numpy.array(data).astype('double')
  60         dset = fd.create_dataset(dsname, data=fdata)
  61         fd.close()
  62 
  63 if HAVE_HDF5:
  64     HDF5Exporter.register()
  65
  [end of pyqtgraph/exporters/HDF5Exporter.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/pyqtgraph/exporters/HDF5Exporter.py b/pyqtgraph/exporters/HDF5Exporter.py
  --- a/pyqtgraph/exporters/HDF5Exporter.py
  +++ b/pyqtgraph/exporters/HDF5Exporter.py
  @@ -44,20 +44,27 @@
           data = []
   
           appendAllX = self.params['columnMode'] == '(x,y) per plot'
  -        #print dir(self.item.curves[0])
  -        tlen = 0
  -        for i, c in enumerate(self.item.curves):
  -            d = c.getData()
  -            if i > 0 and len(d[0]) != tlen:
  -                raise ValueError ("HDF5 Export requires all curves in plot to have same length")
  -            if appendAllX or i == 0:
  -                data.append(d[0])
  -                tlen = len(d[0])
  -            data.append(d[1])
  +        # Check if the arrays are ragged
  +        len_first = len(self.item.curves[0].getData()[0]) if self.item.curves[0] else None
  +        ragged = any(len(i.getData()[0]) != len_first for i in self.item.curves)
   
  +        if ragged:
  +            dgroup = fd.create_group(dsname)
  +            for i, c in enumerate(self.item.curves):
  +                d = c.getData()
  +                fdata = numpy.array([d[0], d[1]]).astype('double')
  +                cname = c.name() if c.name() is not None else str(i)
  +                dset = dgroup.create_dataset(cname, data=fdata)
  +        else:
  +            for i, c in enumerate(self.item.curves):
  +                d = c.getData()
  +                if appendAllX or i == 0:
  +                    data.append(d[0])
  +                data.append(d[1])
  +
  +            fdata = numpy.array(data).astype('double')
  +            dset = fd.create_dataset(dsname, data=fdata)
   
  -        fdata = numpy.array(data).astype('double')
  -        dset = fd.create_dataset(dsname, data=fdata)
           fd.close()
   
   if HAVE_HDF5:
  
verification_info: {"golden_diff": "diff --git a/pyqtgraph/exporters/HDF5Exporter.py b/pyqtgraph/exporters/HDF5Exporter.py\n--- a/pyqtgraph/exporters/HDF5Exporter.py\n+++ b/pyqtgraph/exporters/HDF5Exporter.py\n@@ -44,20 +44,27 @@\n         data = []\n \n         appendAllX = self.params['columnMode'] == '(x,y) per plot'\n-        #print dir(self.item.curves[0])\n-        tlen = 0\n-        for i, c in enumerate(self.item.curves):\n-            d = c.getData()\n-            if i > 0 and len(d[0]) != tlen:\n-                raise ValueError (\"HDF5 Export requires all curves in plot to have same length\")\n-            if appendAllX or i == 0:\n-                data.append(d[0])\n-                tlen = len(d[0])\n-            data.append(d[1])\n+        # Check if the arrays are ragged\n+        len_first = len(self.item.curves[0].getData()[0]) if self.item.curves[0] else None\n+        ragged = any(len(i.getData()[0]) != len_first for i in self.item.curves)\n \n+        if ragged:\n+            dgroup = fd.create_group(dsname)\n+            for i, c in enumerate(self.item.curves):\n+                d = c.getData()\n+                fdata = numpy.array([d[0], d[1]]).astype('double')\n+                cname = c.name() if c.name() is not None else str(i)\n+                dset = dgroup.create_dataset(cname, data=fdata)\n+        else:\n+            for i, c in enumerate(self.item.curves):\n+                d = c.getData()\n+                if appendAllX or i == 0:\n+                    data.append(d[0])\n+                data.append(d[1])\n+\n+            fdata = numpy.array(data).astype('double')\n+            dset = fd.create_dataset(dsname, data=fdata)\n \n-        fdata = numpy.array(data).astype('double')\n-        dset = fd.create_dataset(dsname, data=fdata)\n         fd.close()\n \n if HAVE_HDF5:\n", "issue": "HDF5Exporter: throws error when curves aren't the same length\nWhen trying to save data from a graph as an hdf5 file, the HDF5Exporter throws and error when you have multiple curves with differing lengths. This looks to be because the numpy.array(data).astype('double') can't handle lists with different lengths. Below is a traceback from the error. This occurs when trying to save data from the \"Multiple curves\" graph in the \"Basic Plotting\" example.\r\n\r\n````\r\nTraceback (most recent call last):\r\n  File \"/home/jchrist/PycharmProjects/lib/python3.5/site-packages/pyqtgraph/exporters/Exporter.py\", line 77, in fileSaveFinished\r\n    self.export(fileName=fileName, **self.fileDialog.opts)\r\n  File \"/home/jchrist/PycharmProjects/lib/python3.5/site-packages/pyqtgraph/exporters/HDF5Exporter.py\", line 55, in export\r\n    fdata = numpy.array(data).astype('double')\r\nValueError: setting an array element with a sequence.\r\n````\n", "before_files": [{"content": "from ..Qt import QtGui, QtCore\nfrom .Exporter import Exporter\nfrom ..parametertree import Parameter\nfrom .. import PlotItem\n\nimport numpy \ntry:\n    import h5py\n    HAVE_HDF5 = True\nexcept ImportError:\n    HAVE_HDF5 = False\n    \n__all__ = ['HDF5Exporter']\n\n    \nclass HDF5Exporter(Exporter):\n    Name = \"HDF5 Export: plot (x,y)\"\n    windows = []\n    allowCopy = False\n\n    def __init__(self, item):\n        Exporter.__init__(self, item)\n        self.params = Parameter(name='params', type='group', children=[\n            {'name': 'Name', 'type': 'str', 'value': 'Export',},\n            {'name': 'columnMode', 'type': 'list', 'values': ['(x,y) per plot', '(x,y,y,y) for all plots']},\n        ])\n        \n    def parameters(self):\n        return self.params\n    \n    def export(self, fileName=None):\n        if not HAVE_HDF5:\n            raise RuntimeError(\"This exporter requires the h5py package, \"\n                               \"but it was not importable.\")\n        \n        if not isinstance(self.item, PlotItem):\n            raise Exception(\"Must have a PlotItem selected for HDF5 export.\")\n        \n        if fileName is None:\n            self.fileSaveDialog(filter=[\"*.h5\", \"*.hdf\", \"*.hd5\"])\n            return\n        dsname = self.params['Name']\n        fd = h5py.File(fileName, 'a') # forces append to file... 'w' doesn't seem to \"delete/overwrite\"\n        data = []\n\n        appendAllX = self.params['columnMode'] == '(x,y) per plot'\n        #print dir(self.item.curves[0])\n        tlen = 0\n        for i, c in enumerate(self.item.curves):\n            d = c.getData()\n            if i > 0 and len(d[0]) != tlen:\n                raise ValueError (\"HDF5 Export requires all curves in plot to have same length\")\n            if appendAllX or i == 0:\n                data.append(d[0])\n                tlen = len(d[0])\n            data.append(d[1])\n\n\n        fdata = numpy.array(data).astype('double')\n        dset = fd.create_dataset(dsname, data=fdata)\n        fd.close()\n\nif HAVE_HDF5:\n    HDF5Exporter.register()\n", "path": "pyqtgraph/exporters/HDF5Exporter.py"}]}