We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Deprecate columns in Data
Not a huge deal, but having both `columns` and `fields` in `Data` could potentially confuse new users.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `blaze/interactive.py`
Content:
```
1 from __future__ import absolute_import, division, print_function
2 
3 import datashape
4 import datetime
5 import operator
6 import itertools
7 import warnings
8 
9 from collections import Iterator
10 from functools import reduce
11 
12 from datashape import discover, Tuple, Record, DataShape, var
13 from datashape.predicates import iscollection, isscalar, isrecord, istabular
14 
15 from pandas import DataFrame, Series
16 
17 import numpy as np
18 
19 from odo import resource, odo
20 from odo.utils import ignoring
21 
22 from .expr import Expr, Symbol, ndim
23 from .dispatch import dispatch
24 from .compatibility import _strtypes
25 
26 
27 __all__ = ['Data', 'Table', 'into', 'to_html']
28 
29 
30 names = ('_%d' % i for i in itertools.count(1))
31 not_an_iterator = []
32 
33 
34 with ignoring(ImportError):
35     import bcolz
36     not_an_iterator.append(bcolz.carray)
37 
38 
39 with ignoring(ImportError):
40     import pymongo
41     not_an_iterator.append(pymongo.collection.Collection)
42     not_an_iterator.append(pymongo.database.Database)
43 
44 
45 def Data(data, dshape=None, name=None, fields=None, columns=None, schema=None,
46          **kwargs):
47     sub_uri = ''
48     if isinstance(data, _strtypes):
49         if '::' in data:
50             data, sub_uri = data.split('::')
51         data = resource(data, schema=schema, dshape=dshape, columns=columns,
52                         **kwargs)
53     if (isinstance(data, Iterator) and
54             not isinstance(data, tuple(not_an_iterator))):
55         data = tuple(data)
56     if columns:
57         warnings.warn("columns kwarg deprecated.  Use fields instead",
58                       DeprecationWarning)
59     if columns and not fields:
60         fields = columns
61     if schema and dshape:
62         raise ValueError("Please specify one of schema= or dshape= keyword"
63                          " arguments")
64     if schema and not dshape:
65         dshape = var * schema
66     if dshape and isinstance(dshape, _strtypes):
67         dshape = datashape.dshape(dshape)
68     if not dshape:
69         dshape = discover(data)
70         types = None
71         if isinstance(dshape.measure, Tuple) and fields:
72             types = dshape[1].dshapes
73             schema = Record(list(zip(fields, types)))
74             dshape = DataShape(*(dshape.shape + (schema,)))
75         elif isscalar(dshape.measure) and fields:
76             types = (dshape.measure,) * int(dshape[-2])
77             schema = Record(list(zip(fields, types)))
78             dshape = DataShape(*(dshape.shape[:-1] + (schema,)))
79         elif isrecord(dshape.measure) and fields:
80             ds = discover(data)
81             assert isrecord(ds.measure)
82             names = ds.measure.names
83             if names != fields:
84                 raise ValueError('data column names %s\n'
85                                  '\tnot equal to fields parameter %s,\n'
86                                  '\tuse Data(data).relabel(%s) to rename fields'
87                                  % (names,
88                                     fields,
89                                     ', '.join('%s=%r' % (k, v)
90                                               for k, v in zip(names, fields))))
91             types = dshape.measure.types
92             schema = Record(list(zip(fields, types)))
93             dshape = DataShape(*(dshape.shape + (schema,)))
94 
95     ds = datashape.dshape(dshape)
96     result = InteractiveSymbol(data, ds, name)
97 
98     if sub_uri:
99         for field in sub_uri.split('/'):
100             if field:
101                 result = result[field]
102 
103     return result
104 
105 
106 class InteractiveSymbol(Symbol):
107     """Interactive data.
108 
109     The ``Data`` object presents a familiar view onto a variety of forms of
110     data.  This user-level object provides an interactive experience to using
111     Blaze's abstract expressions.
112 
113     Parameters
114     ----------
115     data : object
116         Any type with ``discover`` and ``compute`` implementations
117     fields : list, optional
118         Field or column names, will be inferred from datasource if possible
119     dshape : str or DataShape, optional
120         DataShape describing input data
121     name : str, optional
122         A name for the data.
123 
124     Examples
125     --------
126     >>> t = Data([(1, 'Alice', 100),
127     ...           (2, 'Bob', -200),
128     ...           (3, 'Charlie', 300),
129     ...           (4, 'Denis', 400),
130     ...           (5, 'Edith', -500)],
131     ...          fields=['id', 'name', 'balance'])
132     >>> t[t.balance < 0].name
133         name
134     0    Bob
135     1  Edith
136     """
137     __slots__ = 'data', 'dshape', '_name'
138 
139     def __init__(self, data, dshape, name=None):
140         self.data = data
141         self.dshape = dshape
142         self._name = name or (next(names)
143                               if isrecord(dshape.measure)
144                               else None)
145 
146     def _resources(self):
147         return {self: self.data}
148 
149     @property
150     def _args(self):
151         return id(self.data), self.dshape, self._name
152 
153     def __setstate__(self, state):
154         for slot, arg in zip(self.__slots__, state):
155             setattr(self, slot, arg)
156 
157 
158 Data.__doc__ = InteractiveSymbol.__doc__
159 
160 
161 def Table(*args, **kwargs):
162     """ Deprecated, see Data instead """
163     warnings.warn("Table is deprecated, use Data instead",
164                   DeprecationWarning)
165     return Data(*args, **kwargs)
166 
167 
168 @dispatch(InteractiveSymbol, dict)
169 def _subs(o, d):
170     return o
171 
172 
173 @dispatch(Expr)
174 def compute(expr, **kwargs):
175     resources = expr._resources()
176     if not resources:
177         raise ValueError("No data resources found")
178     else:
179         return compute(expr, resources, **kwargs)
180 
181 
182 def concrete_head(expr, n=10):
183     """ Return head of computed expression """
184     if not expr._resources():
185         raise ValueError("Expression does not contain data resources")
186     if not iscollection(expr.dshape):
187         return compute(expr)
188 
189     head = expr.head(n + 1)
190 
191     if not iscollection(expr.dshape):
192         return odo(head, object)
193     elif isrecord(expr.dshape.measure):
194         return odo(head, DataFrame)
195     else:
196         df = odo(head, DataFrame)
197         df.columns = [expr._name]
198         return df
199     result = compute(head)
200 
201     if len(result) == 0:
202         return DataFrame(columns=expr.fields)
203     if isrecord(expr.dshape.measure):
204         return odo(result, DataFrame, dshape=expr.dshape)
205     else:
206         df = odo(result, DataFrame, dshape=expr.dshape)
207         df.columns = [expr._name]
208         return df
209 
210 
211 def repr_tables(expr, n=10):
212     result = concrete_head(expr, n).rename(columns={None: ''})
213 
214     if isinstance(result, (DataFrame, Series)):
215         s = repr(result)
216         if len(result) > 10:
217             s = '\n'.join(s.split('\n')[:-1]) + '\n...'
218         return s
219     else:
220         return repr(result)  # pragma: no cover
221 
222 
223 def numel(shape):
224     if var in shape:
225         return None
226     if not shape:
227         return 1
228     return reduce(operator.mul, shape, 1)
229 
230 
231 def short_dshape(ds, nlines=5):
232     s = datashape.coretypes.pprint(ds)
233     lines = s.split('\n')
234     if len(lines) > 5:
235         s = '\n'.join(lines[:nlines]) + '\n  ...'
236     return s
237 
238 
239 def coerce_to(typ, x):
240     try:
241         return typ(x)
242     except TypeError:
243         return odo(x, typ)
244 
245 
246 def coerce_scalar(result, dshape):
247     if 'float' in dshape:
248         return coerce_to(float, result)
249     elif 'int' in dshape:
250         return coerce_to(int, result)
251     elif 'bool' in dshape:
252         return coerce_to(bool, result)
253     elif 'datetime' in dshape:
254         return coerce_to(datetime.datetime, result)
255     elif 'date' in dshape:
256         return coerce_to(datetime.date, result)
257     else:
258         return result
259 
260 
261 def expr_repr(expr, n=10):
262     # Pure Expressions, not interactive
263     if not expr._resources():
264         return str(expr)
265 
266     # Scalars
267     if ndim(expr) == 0 and isscalar(expr.dshape):
268         return repr(coerce_scalar(compute(expr), str(expr.dshape)))
269 
270     # Tables
271     if (ndim(expr) == 1 and (istabular(expr.dshape) or
272                              isscalar(expr.dshape.measure))):
273         return repr_tables(expr, 10)
274 
275     # Smallish arrays
276     if ndim(expr) >= 2 and numel(expr.shape) and numel(expr.shape) < 1000000:
277         return repr(compute(expr))
278 
279     # Other
280     dat = expr._resources().values()
281     if len(dat) == 1:
282         dat = list(dat)[0]  # may be dict_values
283 
284     s = 'Data:       %s' % dat
285     if not isinstance(expr, Symbol):
286         s += '\nExpr:       %s' % str(expr)
287     s += '\nDataShape:  %s' % short_dshape(expr.dshape, nlines=7)
288 
289     return s
290 
291 
292 @dispatch(DataFrame)
293 def to_html(df):
294     return df.to_html()
295 
296 
297 @dispatch(Expr)
298 def to_html(expr):
299     # Tables
300     if not expr._resources() or ndim(expr) != 1:
301         return to_html(repr(expr))
302     return to_html(concrete_head(expr))
303 
304 
305 @dispatch(object)
306 def to_html(o):
307     return repr(o)
308 
309 
310 @dispatch(_strtypes)
311 def to_html(o):
312     return o.replace('\n', '<br>')
313 
314 
315 @dispatch((object, type, str), Expr)
316 def into(a, b, **kwargs):
317     result = compute(b, **kwargs)
318     kwargs['dshape'] = b.dshape
319     return into(a, result, **kwargs)
320 
321 
322 def table_length(expr):
323     try:
324         return expr._len()
325     except ValueError:
326         return compute(expr.count())
327 
328 
329 Expr.__repr__ = expr_repr
330 Expr._repr_html_ = lambda x: to_html(x)
331 Expr.__len__ = table_length
332 
333 
334 def intonumpy(data, dtype=None, **kwargs):
335     # TODO: Don't ignore other kwargs like copy
336     result = odo(data, np.ndarray)
337     if dtype and result.dtype != dtype:
338         result = result.astype(dtype)
339     return result
340 
341 
342 def convert_base(typ, x):
343     x = compute(x)
344     try:
345         return typ(x)
346     except:
347         return typ(odo(x, typ))
348 
349 Expr.__array__ = intonumpy
350 Expr.__int__ = lambda x: convert_base(int, x)
351 Expr.__float__ = lambda x: convert_base(float, x)
352 Expr.__complex__ = lambda x: convert_base(complex, x)
353 Expr.__bool__ = lambda x: convert_base(bool, x)
354 Expr.__nonzero__ = lambda x: convert_base(bool, x)
355 Expr.__iter__ = into(Iterator)
356
```
--- 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/blaze/interactive.py b/blaze/interactive.py
--- a/blaze/interactive.py
+++ b/blaze/interactive.py
@@ -44,6 +44,12 @@
 
 def Data(data, dshape=None, name=None, fields=None, columns=None, schema=None,
          **kwargs):
+    if columns:
+        raise ValueError("columns argument deprecated, use fields instead")
+    if schema and dshape:
+        raise ValueError("Please specify one of schema= or dshape= keyword"
+                         " arguments")
+
     sub_uri = ''
     if isinstance(data, _strtypes):
         if '::' in data:
@@ -53,14 +59,6 @@
     if (isinstance(data, Iterator) and
             not isinstance(data, tuple(not_an_iterator))):
         data = tuple(data)
-    if columns:
-        warnings.warn("columns kwarg deprecated.  Use fields instead",
-                      DeprecationWarning)
-    if columns and not fields:
-        fields = columns
-    if schema and dshape:
-        raise ValueError("Please specify one of schema= or dshape= keyword"
-                         " arguments")
     if schema and not dshape:
         dshape = var * schema
     if dshape and isinstance(dshape, _strtypes):
@@ -83,11 +81,12 @@
             if names != fields:
                 raise ValueError('data column names %s\n'
                                  '\tnot equal to fields parameter %s,\n'
-                                 '\tuse Data(data).relabel(%s) to rename fields'
-                                 % (names,
-                                    fields,
-                                    ', '.join('%s=%r' % (k, v)
-                                              for k, v in zip(names, fields))))
+                                 '\tuse Data(data).relabel(%s) to rename '
+                                 'fields' % (names,
+                                             fields,
+                                             ', '.join('%s=%r' % (k, v)
+                                                       for k, v in
+                                                       zip(names, fields))))
             types = dshape.measure.types
             schema = Record(list(zip(fields, types)))
             dshape = DataShape(*(dshape.shape + (schema,)))

{"golden_diff": "diff --git a/blaze/interactive.py b/blaze/interactive.py\n--- a/blaze/interactive.py\n+++ b/blaze/interactive.py\n@@ -44,6 +44,12 @@\n \n def Data(data, dshape=None, name=None, fields=None, columns=None, schema=None,\n          **kwargs):\n+    if columns:\n+        raise ValueError(\"columns argument deprecated, use fields instead\")\n+    if schema and dshape:\n+        raise ValueError(\"Please specify one of schema= or dshape= keyword\"\n+                         \" arguments\")\n+\n     sub_uri = ''\n     if isinstance(data, _strtypes):\n         if '::' in data:\n@@ -53,14 +59,6 @@\n     if (isinstance(data, Iterator) and\n             not isinstance(data, tuple(not_an_iterator))):\n         data = tuple(data)\n-    if columns:\n-        warnings.warn(\"columns kwarg deprecated.  Use fields instead\",\n-                      DeprecationWarning)\n-    if columns and not fields:\n-        fields = columns\n-    if schema and dshape:\n-        raise ValueError(\"Please specify one of schema= or dshape= keyword\"\n-                         \" arguments\")\n     if schema and not dshape:\n         dshape = var * schema\n     if dshape and isinstance(dshape, _strtypes):\n@@ -83,11 +81,12 @@\n             if names != fields:\n                 raise ValueError('data column names %s\\n'\n                                  '\\tnot equal to fields parameter %s,\\n'\n-                                 '\\tuse Data(data).relabel(%s) to rename fields'\n-                                 % (names,\n-                                    fields,\n-                                    ', '.join('%s=%r' % (k, v)\n-                                              for k, v in zip(names, fields))))\n+                                 '\\tuse Data(data).relabel(%s) to rename '\n+                                 'fields' % (names,\n+                                             fields,\n+                                             ', '.join('%s=%r' % (k, v)\n+                                                       for k, v in\n+                                                       zip(names, fields))))\n             types = dshape.measure.types\n             schema = Record(list(zip(fields, types)))\n             dshape = DataShape(*(dshape.shape + (schema,)))\n", "issue": "Deprecate columns in Data\nNot a huge deal, but having both `columns` and `fields` in `Data` could potentially confuse new users.\n\n", "before_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport datashape\nimport datetime\nimport operator\nimport itertools\nimport warnings\n\nfrom collections import Iterator\nfrom functools import reduce\n\nfrom datashape import discover, Tuple, Record, DataShape, var\nfrom datashape.predicates import iscollection, isscalar, isrecord, istabular\n\nfrom pandas import DataFrame, Series\n\nimport numpy as np\n\nfrom odo import resource, odo\nfrom odo.utils import ignoring\n\nfrom .expr import Expr, Symbol, ndim\nfrom .dispatch import dispatch\nfrom .compatibility import _strtypes\n\n\n__all__ = ['Data', 'Table', 'into', 'to_html']\n\n\nnames = ('_%d' % i for i in itertools.count(1))\nnot_an_iterator = []\n\n\nwith ignoring(ImportError):\n    import bcolz\n    not_an_iterator.append(bcolz.carray)\n\n\nwith ignoring(ImportError):\n    import pymongo\n    not_an_iterator.append(pymongo.collection.Collection)\n    not_an_iterator.append(pymongo.database.Database)\n\n\ndef Data(data, dshape=None, name=None, fields=None, columns=None, schema=None,\n         **kwargs):\n    sub_uri = ''\n    if isinstance(data, _strtypes):\n        if '::' in data:\n            data, sub_uri = data.split('::')\n        data = resource(data, schema=schema, dshape=dshape, columns=columns,\n                        **kwargs)\n    if (isinstance(data, Iterator) and\n            not isinstance(data, tuple(not_an_iterator))):\n        data = tuple(data)\n    if columns:\n        warnings.warn(\"columns kwarg deprecated.  Use fields instead\",\n                      DeprecationWarning)\n    if columns and not fields:\n        fields = columns\n    if schema and dshape:\n        raise ValueError(\"Please specify one of schema= or dshape= keyword\"\n                         \" arguments\")\n    if schema and not dshape:\n        dshape = var * schema\n    if dshape and isinstance(dshape, _strtypes):\n        dshape = datashape.dshape(dshape)\n    if not dshape:\n        dshape = discover(data)\n        types = None\n        if isinstance(dshape.measure, Tuple) and fields:\n            types = dshape[1].dshapes\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape + (schema,)))\n        elif isscalar(dshape.measure) and fields:\n            types = (dshape.measure,) * int(dshape[-2])\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape[:-1] + (schema,)))\n        elif isrecord(dshape.measure) and fields:\n            ds = discover(data)\n            assert isrecord(ds.measure)\n            names = ds.measure.names\n            if names != fields:\n                raise ValueError('data column names %s\\n'\n                                 '\\tnot equal to fields parameter %s,\\n'\n                                 '\\tuse Data(data).relabel(%s) to rename fields'\n                                 % (names,\n                                    fields,\n                                    ', '.join('%s=%r' % (k, v)\n                                              for k, v in zip(names, fields))))\n            types = dshape.measure.types\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape + (schema,)))\n\n    ds = datashape.dshape(dshape)\n    result = InteractiveSymbol(data, ds, name)\n\n    if sub_uri:\n        for field in sub_uri.split('/'):\n            if field:\n                result = result[field]\n\n    return result\n\n\nclass InteractiveSymbol(Symbol):\n    \"\"\"Interactive data.\n\n    The ``Data`` object presents a familiar view onto a variety of forms of\n    data.  This user-level object provides an interactive experience to using\n    Blaze's abstract expressions.\n\n    Parameters\n    ----------\n    data : object\n        Any type with ``discover`` and ``compute`` implementations\n    fields : list, optional\n        Field or column names, will be inferred from datasource if possible\n    dshape : str or DataShape, optional\n        DataShape describing input data\n    name : str, optional\n        A name for the data.\n\n    Examples\n    --------\n    >>> t = Data([(1, 'Alice', 100),\n    ...           (2, 'Bob', -200),\n    ...           (3, 'Charlie', 300),\n    ...           (4, 'Denis', 400),\n    ...           (5, 'Edith', -500)],\n    ...          fields=['id', 'name', 'balance'])\n    >>> t[t.balance < 0].name\n        name\n    0    Bob\n    1  Edith\n    \"\"\"\n    __slots__ = 'data', 'dshape', '_name'\n\n    def __init__(self, data, dshape, name=None):\n        self.data = data\n        self.dshape = dshape\n        self._name = name or (next(names)\n                              if isrecord(dshape.measure)\n                              else None)\n\n    def _resources(self):\n        return {self: self.data}\n\n    @property\n    def _args(self):\n        return id(self.data), self.dshape, self._name\n\n    def __setstate__(self, state):\n        for slot, arg in zip(self.__slots__, state):\n            setattr(self, slot, arg)\n\n\nData.__doc__ = InteractiveSymbol.__doc__\n\n\ndef Table(*args, **kwargs):\n    \"\"\" Deprecated, see Data instead \"\"\"\n    warnings.warn(\"Table is deprecated, use Data instead\",\n                  DeprecationWarning)\n    return Data(*args, **kwargs)\n\n\n@dispatch(InteractiveSymbol, dict)\ndef _subs(o, d):\n    return o\n\n\n@dispatch(Expr)\ndef compute(expr, **kwargs):\n    resources = expr._resources()\n    if not resources:\n        raise ValueError(\"No data resources found\")\n    else:\n        return compute(expr, resources, **kwargs)\n\n\ndef concrete_head(expr, n=10):\n    \"\"\" Return head of computed expression \"\"\"\n    if not expr._resources():\n        raise ValueError(\"Expression does not contain data resources\")\n    if not iscollection(expr.dshape):\n        return compute(expr)\n\n    head = expr.head(n + 1)\n\n    if not iscollection(expr.dshape):\n        return odo(head, object)\n    elif isrecord(expr.dshape.measure):\n        return odo(head, DataFrame)\n    else:\n        df = odo(head, DataFrame)\n        df.columns = [expr._name]\n        return df\n    result = compute(head)\n\n    if len(result) == 0:\n        return DataFrame(columns=expr.fields)\n    if isrecord(expr.dshape.measure):\n        return odo(result, DataFrame, dshape=expr.dshape)\n    else:\n        df = odo(result, DataFrame, dshape=expr.dshape)\n        df.columns = [expr._name]\n        return df\n\n\ndef repr_tables(expr, n=10):\n    result = concrete_head(expr, n).rename(columns={None: ''})\n\n    if isinstance(result, (DataFrame, Series)):\n        s = repr(result)\n        if len(result) > 10:\n            s = '\\n'.join(s.split('\\n')[:-1]) + '\\n...'\n        return s\n    else:\n        return repr(result)  # pragma: no cover\n\n\ndef numel(shape):\n    if var in shape:\n        return None\n    if not shape:\n        return 1\n    return reduce(operator.mul, shape, 1)\n\n\ndef short_dshape(ds, nlines=5):\n    s = datashape.coretypes.pprint(ds)\n    lines = s.split('\\n')\n    if len(lines) > 5:\n        s = '\\n'.join(lines[:nlines]) + '\\n  ...'\n    return s\n\n\ndef coerce_to(typ, x):\n    try:\n        return typ(x)\n    except TypeError:\n        return odo(x, typ)\n\n\ndef coerce_scalar(result, dshape):\n    if 'float' in dshape:\n        return coerce_to(float, result)\n    elif 'int' in dshape:\n        return coerce_to(int, result)\n    elif 'bool' in dshape:\n        return coerce_to(bool, result)\n    elif 'datetime' in dshape:\n        return coerce_to(datetime.datetime, result)\n    elif 'date' in dshape:\n        return coerce_to(datetime.date, result)\n    else:\n        return result\n\n\ndef expr_repr(expr, n=10):\n    # Pure Expressions, not interactive\n    if not expr._resources():\n        return str(expr)\n\n    # Scalars\n    if ndim(expr) == 0 and isscalar(expr.dshape):\n        return repr(coerce_scalar(compute(expr), str(expr.dshape)))\n\n    # Tables\n    if (ndim(expr) == 1 and (istabular(expr.dshape) or\n                             isscalar(expr.dshape.measure))):\n        return repr_tables(expr, 10)\n\n    # Smallish arrays\n    if ndim(expr) >= 2 and numel(expr.shape) and numel(expr.shape) < 1000000:\n        return repr(compute(expr))\n\n    # Other\n    dat = expr._resources().values()\n    if len(dat) == 1:\n        dat = list(dat)[0]  # may be dict_values\n\n    s = 'Data:       %s' % dat\n    if not isinstance(expr, Symbol):\n        s += '\\nExpr:       %s' % str(expr)\n    s += '\\nDataShape:  %s' % short_dshape(expr.dshape, nlines=7)\n\n    return s\n\n\n@dispatch(DataFrame)\ndef to_html(df):\n    return df.to_html()\n\n\n@dispatch(Expr)\ndef to_html(expr):\n    # Tables\n    if not expr._resources() or ndim(expr) != 1:\n        return to_html(repr(expr))\n    return to_html(concrete_head(expr))\n\n\n@dispatch(object)\ndef to_html(o):\n    return repr(o)\n\n\n@dispatch(_strtypes)\ndef to_html(o):\n    return o.replace('\\n', '<br>')\n\n\n@dispatch((object, type, str), Expr)\ndef into(a, b, **kwargs):\n    result = compute(b, **kwargs)\n    kwargs['dshape'] = b.dshape\n    return into(a, result, **kwargs)\n\n\ndef table_length(expr):\n    try:\n        return expr._len()\n    except ValueError:\n        return compute(expr.count())\n\n\nExpr.__repr__ = expr_repr\nExpr._repr_html_ = lambda x: to_html(x)\nExpr.__len__ = table_length\n\n\ndef intonumpy(data, dtype=None, **kwargs):\n    # TODO: Don't ignore other kwargs like copy\n    result = odo(data, np.ndarray)\n    if dtype and result.dtype != dtype:\n        result = result.astype(dtype)\n    return result\n\n\ndef convert_base(typ, x):\n    x = compute(x)\n    try:\n        return typ(x)\n    except:\n        return typ(odo(x, typ))\n\nExpr.__array__ = intonumpy\nExpr.__int__ = lambda x: convert_base(int, x)\nExpr.__float__ = lambda x: convert_base(float, x)\nExpr.__complex__ = lambda x: convert_base(complex, x)\nExpr.__bool__ = lambda x: convert_base(bool, x)\nExpr.__nonzero__ = lambda x: convert_base(bool, x)\nExpr.__iter__ = into(Iterator)\n", "path": "blaze/interactive.py"}], "after_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport datashape\nimport datetime\nimport operator\nimport itertools\nimport warnings\n\nfrom collections import Iterator\nfrom functools import reduce\n\nfrom datashape import discover, Tuple, Record, DataShape, var\nfrom datashape.predicates import iscollection, isscalar, isrecord, istabular\n\nfrom pandas import DataFrame, Series\n\nimport numpy as np\n\nfrom odo import resource, odo\nfrom odo.utils import ignoring\n\nfrom .expr import Expr, Symbol, ndim\nfrom .dispatch import dispatch\nfrom .compatibility import _strtypes\n\n\n__all__ = ['Data', 'Table', 'into', 'to_html']\n\n\nnames = ('_%d' % i for i in itertools.count(1))\nnot_an_iterator = []\n\n\nwith ignoring(ImportError):\n    import bcolz\n    not_an_iterator.append(bcolz.carray)\n\n\nwith ignoring(ImportError):\n    import pymongo\n    not_an_iterator.append(pymongo.collection.Collection)\n    not_an_iterator.append(pymongo.database.Database)\n\n\ndef Data(data, dshape=None, name=None, fields=None, columns=None, schema=None,\n         **kwargs):\n    if columns:\n        raise ValueError(\"columns argument deprecated, use fields instead\")\n    if schema and dshape:\n        raise ValueError(\"Please specify one of schema= or dshape= keyword\"\n                         \" arguments\")\n\n    sub_uri = ''\n    if isinstance(data, _strtypes):\n        if '::' in data:\n            data, sub_uri = data.split('::')\n        data = resource(data, schema=schema, dshape=dshape, columns=columns,\n                        **kwargs)\n    if (isinstance(data, Iterator) and\n            not isinstance(data, tuple(not_an_iterator))):\n        data = tuple(data)\n    if schema and not dshape:\n        dshape = var * schema\n    if dshape and isinstance(dshape, _strtypes):\n        dshape = datashape.dshape(dshape)\n    if not dshape:\n        dshape = discover(data)\n        types = None\n        if isinstance(dshape.measure, Tuple) and fields:\n            types = dshape[1].dshapes\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape + (schema,)))\n        elif isscalar(dshape.measure) and fields:\n            types = (dshape.measure,) * int(dshape[-2])\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape[:-1] + (schema,)))\n        elif isrecord(dshape.measure) and fields:\n            ds = discover(data)\n            assert isrecord(ds.measure)\n            names = ds.measure.names\n            if names != fields:\n                raise ValueError('data column names %s\\n'\n                                 '\\tnot equal to fields parameter %s,\\n'\n                                 '\\tuse Data(data).relabel(%s) to rename '\n                                 'fields' % (names,\n                                             fields,\n                                             ', '.join('%s=%r' % (k, v)\n                                                       for k, v in\n                                                       zip(names, fields))))\n            types = dshape.measure.types\n            schema = Record(list(zip(fields, types)))\n            dshape = DataShape(*(dshape.shape + (schema,)))\n\n    ds = datashape.dshape(dshape)\n    result = InteractiveSymbol(data, ds, name)\n\n    if sub_uri:\n        for field in sub_uri.split('/'):\n            if field:\n                result = result[field]\n\n    return result\n\n\nclass InteractiveSymbol(Symbol):\n    \"\"\"Interactive data.\n\n    The ``Data`` object presents a familiar view onto a variety of forms of\n    data.  This user-level object provides an interactive experience to using\n    Blaze's abstract expressions.\n\n    Parameters\n    ----------\n    data : object\n        Any type with ``discover`` and ``compute`` implementations\n    fields : list, optional\n        Field or column names, will be inferred from datasource if possible\n    dshape : str or DataShape, optional\n        DataShape describing input data\n    name : str, optional\n        A name for the data.\n\n    Examples\n    --------\n    >>> t = Data([(1, 'Alice', 100),\n    ...           (2, 'Bob', -200),\n    ...           (3, 'Charlie', 300),\n    ...           (4, 'Denis', 400),\n    ...           (5, 'Edith', -500)],\n    ...          fields=['id', 'name', 'balance'])\n    >>> t[t.balance < 0].name\n        name\n    0    Bob\n    1  Edith\n    \"\"\"\n    __slots__ = 'data', 'dshape', '_name'\n\n    def __init__(self, data, dshape, name=None):\n        self.data = data\n        self.dshape = dshape\n        self._name = name or (next(names)\n                              if isrecord(dshape.measure)\n                              else None)\n\n    def _resources(self):\n        return {self: self.data}\n\n    @property\n    def _args(self):\n        return id(self.data), self.dshape, self._name\n\n    def __setstate__(self, state):\n        for slot, arg in zip(self.__slots__, state):\n            setattr(self, slot, arg)\n\n\nData.__doc__ = InteractiveSymbol.__doc__\n\n\ndef Table(*args, **kwargs):\n    \"\"\" Deprecated, see Data instead \"\"\"\n    warnings.warn(\"Table is deprecated, use Data instead\",\n                  DeprecationWarning)\n    return Data(*args, **kwargs)\n\n\n@dispatch(InteractiveSymbol, dict)\ndef _subs(o, d):\n    return o\n\n\n@dispatch(Expr)\ndef compute(expr, **kwargs):\n    resources = expr._resources()\n    if not resources:\n        raise ValueError(\"No data resources found\")\n    else:\n        return compute(expr, resources, **kwargs)\n\n\ndef concrete_head(expr, n=10):\n    \"\"\" Return head of computed expression \"\"\"\n    if not expr._resources():\n        raise ValueError(\"Expression does not contain data resources\")\n    if not iscollection(expr.dshape):\n        return compute(expr)\n\n    head = expr.head(n + 1)\n\n    if not iscollection(expr.dshape):\n        return odo(head, object)\n    elif isrecord(expr.dshape.measure):\n        return odo(head, DataFrame)\n    else:\n        df = odo(head, DataFrame)\n        df.columns = [expr._name]\n        return df\n    result = compute(head)\n\n    if len(result) == 0:\n        return DataFrame(columns=expr.fields)\n    if isrecord(expr.dshape.measure):\n        return odo(result, DataFrame, dshape=expr.dshape)\n    else:\n        df = odo(result, DataFrame, dshape=expr.dshape)\n        df.columns = [expr._name]\n        return df\n\n\ndef repr_tables(expr, n=10):\n    result = concrete_head(expr, n).rename(columns={None: ''})\n\n    if isinstance(result, (DataFrame, Series)):\n        s = repr(result)\n        if len(result) > 10:\n            s = '\\n'.join(s.split('\\n')[:-1]) + '\\n...'\n        return s\n    else:\n        return repr(result)  # pragma: no cover\n\n\ndef numel(shape):\n    if var in shape:\n        return None\n    if not shape:\n        return 1\n    return reduce(operator.mul, shape, 1)\n\n\ndef short_dshape(ds, nlines=5):\n    s = datashape.coretypes.pprint(ds)\n    lines = s.split('\\n')\n    if len(lines) > 5:\n        s = '\\n'.join(lines[:nlines]) + '\\n  ...'\n    return s\n\n\ndef coerce_to(typ, x):\n    try:\n        return typ(x)\n    except TypeError:\n        return odo(x, typ)\n\n\ndef coerce_scalar(result, dshape):\n    if 'float' in dshape:\n        return coerce_to(float, result)\n    elif 'int' in dshape:\n        return coerce_to(int, result)\n    elif 'bool' in dshape:\n        return coerce_to(bool, result)\n    elif 'datetime' in dshape:\n        return coerce_to(datetime.datetime, result)\n    elif 'date' in dshape:\n        return coerce_to(datetime.date, result)\n    else:\n        return result\n\n\ndef expr_repr(expr, n=10):\n    # Pure Expressions, not interactive\n    if not expr._resources():\n        return str(expr)\n\n    # Scalars\n    if ndim(expr) == 0 and isscalar(expr.dshape):\n        return repr(coerce_scalar(compute(expr), str(expr.dshape)))\n\n    # Tables\n    if (ndim(expr) == 1 and (istabular(expr.dshape) or\n                             isscalar(expr.dshape.measure))):\n        return repr_tables(expr, 10)\n\n    # Smallish arrays\n    if ndim(expr) >= 2 and numel(expr.shape) and numel(expr.shape) < 1000000:\n        return repr(compute(expr))\n\n    # Other\n    dat = expr._resources().values()\n    if len(dat) == 1:\n        dat = list(dat)[0]  # may be dict_values\n\n    s = 'Data:       %s' % dat\n    if not isinstance(expr, Symbol):\n        s += '\\nExpr:       %s' % str(expr)\n    s += '\\nDataShape:  %s' % short_dshape(expr.dshape, nlines=7)\n\n    return s\n\n\n@dispatch(DataFrame)\ndef to_html(df):\n    return df.to_html()\n\n\n@dispatch(Expr)\ndef to_html(expr):\n    # Tables\n    if not expr._resources() or ndim(expr) != 1:\n        return to_html(repr(expr))\n    return to_html(concrete_head(expr))\n\n\n@dispatch(object)\ndef to_html(o):\n    return repr(o)\n\n\n@dispatch(_strtypes)\ndef to_html(o):\n    return o.replace('\\n', '<br>')\n\n\n@dispatch((object, type, str), Expr)\ndef into(a, b, **kwargs):\n    result = compute(b, **kwargs)\n    kwargs['dshape'] = b.dshape\n    return into(a, result, **kwargs)\n\n\ndef table_length(expr):\n    try:\n        return expr._len()\n    except ValueError:\n        return compute(expr.count())\n\n\nExpr.__repr__ = expr_repr\nExpr._repr_html_ = lambda x: to_html(x)\nExpr.__len__ = table_length\n\n\ndef intonumpy(data, dtype=None, **kwargs):\n    # TODO: Don't ignore other kwargs like copy\n    result = odo(data, np.ndarray)\n    if dtype and result.dtype != dtype:\n        result = result.astype(dtype)\n    return result\n\n\ndef convert_base(typ, x):\n    x = compute(x)\n    try:\n        return typ(x)\n    except:\n        return typ(odo(x, typ))\n\nExpr.__array__ = intonumpy\nExpr.__int__ = lambda x: convert_base(int, x)\nExpr.__float__ = lambda x: convert_base(float, x)\nExpr.__complex__ = lambda x: convert_base(complex, x)\nExpr.__bool__ = lambda x: convert_base(bool, x)\nExpr.__nonzero__ = lambda x: convert_base(bool, x)\nExpr.__iter__ = into(Iterator)\n", "path": "blaze/interactive.py"}]}