prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  String Accessors in Converted DataFrame Columns
  Whenever I try to access strings in a dataframe which are previously converted to strings (ie. datall[['A']] = datall[['A']].applymap(str) and then datall['A']=datall['A'].str[:5]) I get a TypeError: 'StringAccessor' object has no attribute '__getitem__'.
  
  This is reproducible as follows:
  
  ```
  import pandas as pd
  import dask.dataframe as dd
  import numpy as np
  
  def float_apply(x):
      try:
          return float(x)
      except ValueError:
          return float('nan')
  
  def string_apply(x):
      try:
          return str(x)
      except ValueError:
          return str('nan')
  
  df = pd.DataFrame(np.random.random_integers(0,6,size=(20, 6)), columns=list('ABCDEF'))
  
  data = dd.from_pandas(df, npartitions = 2)
  
  data=data.applymap(float_apply)
  
  data[['A']] = data[['A']].applymap(string_apply)
  data['A'] = data['A'].str[:1]
  
  print data.compute()
  
  ```
  
  This will work with pandas dataframes. If .compute() is run prior to this then it works fine but that is probably suboptimal for large datasets.
  
  </issue>
  <code>
  [start of dask/dataframe/accessor.py]
  1 from __future__ import absolute_import, division, print_function
  2 
  3 import numpy as np
  4 import pandas as pd
  5 from toolz import partial
  6 
  7 from ..utils import derived_from
  8 
  9 
  10 def maybe_wrap_pandas(obj, x):
  11     if isinstance(x, np.ndarray):
  12         if isinstance(obj, pd.Series):
  13             return pd.Series(x, index=obj.index, dtype=x.dtype)
  14         return pd.Index(x)
  15     return x
  16 
  17 
  18 class Accessor(object):
  19     """
  20     Base class for pandas Accessor objects cat, dt, and str.
  21 
  22     Notes
  23     -----
  24     Subclasses should define the following attributes:
  25 
  26     * _accessor
  27     * _accessor_name
  28     """
  29     _not_implemented = set()
  30 
  31     def __init__(self, series):
  32         from .core import Series
  33         if not isinstance(series, Series):
  34             raise ValueError('Accessor cannot be initialized')
  35         self._validate(series)
  36         self._series = series
  37 
  38     def _validate(self, series):
  39         pass
  40 
  41     @staticmethod
  42     def _delegate_property(obj, accessor, attr):
  43         out = getattr(getattr(obj, accessor, obj), attr)
  44         return maybe_wrap_pandas(obj, out)
  45 
  46     @staticmethod
  47     def _delegate_method(obj, accessor, attr, args, kwargs):
  48         out = getattr(getattr(obj, accessor, obj), attr)(*args, **kwargs)
  49         return maybe_wrap_pandas(obj, out)
  50 
  51     def _property_map(self, attr):
  52         meta = self._delegate_property(self._series._meta,
  53                                        self._accessor_name, attr)
  54         token = '%s-%s' % (self._accessor_name, attr)
  55         return self._series.map_partitions(self._delegate_property,
  56                                            self._accessor_name, attr,
  57                                            token=token, meta=meta)
  58 
  59     def _function_map(self, attr, *args, **kwargs):
  60         meta = self._delegate_method(self._series._meta_nonempty,
  61                                      self._accessor_name,  attr, args, kwargs)
  62         token = '%s-%s' % (self._accessor_name, attr)
  63         return self._series.map_partitions(self._delegate_method,
  64                                            self._accessor_name, attr, args,
  65                                            kwargs, meta=meta, token=token)
  66 
  67     @property
  68     def _delegates(self):
  69         return set(dir(self._accessor)).difference(self._not_implemented)
  70 
  71     def __dir__(self):
  72         o = self._delegates
  73         o.update(self.__dict__)
  74         o.update(dir(type(self)))
  75         return list(o)
  76 
  77     def __getattr__(self, key):
  78         if key in self._delegates:
  79             if isinstance(getattr(self._accessor, key), property):
  80                 return self._property_map(key)
  81             else:
  82                 return partial(self._function_map, key)
  83         else:
  84             raise AttributeError(key)
  85 
  86 
  87 class DatetimeAccessor(Accessor):
  88     """ Accessor object for datetimelike properties of the Series values.
  89 
  90     Examples
  91     --------
  92 
  93     >>> s.dt.microsecond  # doctest: +SKIP
  94     """
  95     _accessor = pd.Series.dt
  96     _accessor_name = 'dt'
  97 
  98 
  99 class StringAccessor(Accessor):
  100     """ Accessor object for string properties of the Series values.
  101 
  102     Examples
  103     --------
  104 
  105     >>> s.str.lower()  # doctest: +SKIP
  106     """
  107     _accessor = pd.Series.str
  108     _accessor_name = 'str'
  109     _not_implemented = {'get_dummies'}
  110 
  111     def _validate(self, series):
  112         if not series.dtype == 'object':
  113             raise AttributeError("Can only use .str accessor with object dtype")
  114 
  115     @derived_from(pd.core.strings.StringMethods)
  116     def split(self, pat=None, n=-1):
  117         return self._function_map('split', pat=pat, n=n)
  118
  [end of dask/dataframe/accessor.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/dask/dataframe/accessor.py b/dask/dataframe/accessor.py
  --- a/dask/dataframe/accessor.py
  +++ b/dask/dataframe/accessor.py
  @@ -115,3 +115,12 @@
       @derived_from(pd.core.strings.StringMethods)
       def split(self, pat=None, n=-1):
           return self._function_map('split', pat=pat, n=n)
  +
  +    def __getitem__(self, index):
  +        return self._series.map_partitions(str_get, index,
  +                                           meta=self._series._meta)
  +
  +
  +def str_get(series, index):
  +    """ Implements series.str[index] """
  +    return series.str[index]
  
verification_info: {"golden_diff": "diff --git a/dask/dataframe/accessor.py b/dask/dataframe/accessor.py\n--- a/dask/dataframe/accessor.py\n+++ b/dask/dataframe/accessor.py\n@@ -115,3 +115,12 @@\n     @derived_from(pd.core.strings.StringMethods)\n     def split(self, pat=None, n=-1):\n         return self._function_map('split', pat=pat, n=n)\n+\n+    def __getitem__(self, index):\n+        return self._series.map_partitions(str_get, index,\n+                                           meta=self._series._meta)\n+\n+\n+def str_get(series, index):\n+    \"\"\" Implements series.str[index] \"\"\"\n+    return series.str[index]\n", "issue": "String Accessors in Converted DataFrame Columns\nWhenever I try to access strings in a dataframe which are previously converted to strings (ie. datall[['A']] = datall[['A']].applymap(str) and then datall['A']=datall['A'].str[:5]) I get a TypeError: 'StringAccessor' object has no attribute '__getitem__'.\r\n\r\nThis is reproducible as follows:\r\n\r\n```\r\nimport pandas as pd\r\nimport dask.dataframe as dd\r\nimport numpy as np\r\n\r\ndef float_apply(x):\r\n    try:\r\n        return float(x)\r\n    except ValueError:\r\n        return float('nan')\r\n\r\ndef string_apply(x):\r\n    try:\r\n        return str(x)\r\n    except ValueError:\r\n        return str('nan')\r\n\r\ndf = pd.DataFrame(np.random.random_integers(0,6,size=(20, 6)), columns=list('ABCDEF'))\r\n\r\ndata = dd.from_pandas(df, npartitions = 2)\r\n\r\ndata=data.applymap(float_apply)\r\n\r\ndata[['A']] = data[['A']].applymap(string_apply)\r\ndata['A'] = data['A'].str[:1]\r\n\r\nprint data.compute()\r\n\r\n```\r\n\r\nThis will work with pandas dataframes. If .compute() is run prior to this then it works fine but that is probably suboptimal for large datasets.\n", "before_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport numpy as np\nimport pandas as pd\nfrom toolz import partial\n\nfrom ..utils import derived_from\n\n\ndef maybe_wrap_pandas(obj, x):\n    if isinstance(x, np.ndarray):\n        if isinstance(obj, pd.Series):\n            return pd.Series(x, index=obj.index, dtype=x.dtype)\n        return pd.Index(x)\n    return x\n\n\nclass Accessor(object):\n    \"\"\"\n    Base class for pandas Accessor objects cat, dt, and str.\n\n    Notes\n    -----\n    Subclasses should define the following attributes:\n\n    * _accessor\n    * _accessor_name\n    \"\"\"\n    _not_implemented = set()\n\n    def __init__(self, series):\n        from .core import Series\n        if not isinstance(series, Series):\n            raise ValueError('Accessor cannot be initialized')\n        self._validate(series)\n        self._series = series\n\n    def _validate(self, series):\n        pass\n\n    @staticmethod\n    def _delegate_property(obj, accessor, attr):\n        out = getattr(getattr(obj, accessor, obj), attr)\n        return maybe_wrap_pandas(obj, out)\n\n    @staticmethod\n    def _delegate_method(obj, accessor, attr, args, kwargs):\n        out = getattr(getattr(obj, accessor, obj), attr)(*args, **kwargs)\n        return maybe_wrap_pandas(obj, out)\n\n    def _property_map(self, attr):\n        meta = self._delegate_property(self._series._meta,\n                                       self._accessor_name, attr)\n        token = '%s-%s' % (self._accessor_name, attr)\n        return self._series.map_partitions(self._delegate_property,\n                                           self._accessor_name, attr,\n                                           token=token, meta=meta)\n\n    def _function_map(self, attr, *args, **kwargs):\n        meta = self._delegate_method(self._series._meta_nonempty,\n                                     self._accessor_name,  attr, args, kwargs)\n        token = '%s-%s' % (self._accessor_name, attr)\n        return self._series.map_partitions(self._delegate_method,\n                                           self._accessor_name, attr, args,\n                                           kwargs, meta=meta, token=token)\n\n    @property\n    def _delegates(self):\n        return set(dir(self._accessor)).difference(self._not_implemented)\n\n    def __dir__(self):\n        o = self._delegates\n        o.update(self.__dict__)\n        o.update(dir(type(self)))\n        return list(o)\n\n    def __getattr__(self, key):\n        if key in self._delegates:\n            if isinstance(getattr(self._accessor, key), property):\n                return self._property_map(key)\n            else:\n                return partial(self._function_map, key)\n        else:\n            raise AttributeError(key)\n\n\nclass DatetimeAccessor(Accessor):\n    \"\"\" Accessor object for datetimelike properties of the Series values.\n\n    Examples\n    --------\n\n    >>> s.dt.microsecond  # doctest: +SKIP\n    \"\"\"\n    _accessor = pd.Series.dt\n    _accessor_name = 'dt'\n\n\nclass StringAccessor(Accessor):\n    \"\"\" Accessor object for string properties of the Series values.\n\n    Examples\n    --------\n\n    >>> s.str.lower()  # doctest: +SKIP\n    \"\"\"\n    _accessor = pd.Series.str\n    _accessor_name = 'str'\n    _not_implemented = {'get_dummies'}\n\n    def _validate(self, series):\n        if not series.dtype == 'object':\n            raise AttributeError(\"Can only use .str accessor with object dtype\")\n\n    @derived_from(pd.core.strings.StringMethods)\n    def split(self, pat=None, n=-1):\n        return self._function_map('split', pat=pat, n=n)\n", "path": "dask/dataframe/accessor.py"}]}