Repository: blaze/blaze

Issue:
TypingError: Failed at nopython (nopython frontend)
Following on from my (now resolved) llvmlite problem in ContinuumIO/blaze#959, I am now getting an error in the numba module:

```
In [3]: d = blaze.Data(db)

In [4]: blaze.compute(d[['date']])
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-4-5a07b13ec053> in <module>()
----> 1 blaze.compute(d[['date']])

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\interactive.pyc in compute(expr, **kwargs)
    160         raise ValueError("No data resources found")
    161     else:
--> 162         return compute(expr, resources, **kwargs)
    163 
    164 

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469 
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    191                 "data: %s" % (expr3, scope4))
    192     else:
--> 193         return top_then_bottom_then_top_again_etc(expr3, scope4, **kwargs)
    194 
    195 

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    157     # 1. See if we have a direct computation path with compute_down
    158     try:
--> 159         return compute_down(expr, *leaf_data, **kwargs)
    160     except NotImplementedError:
    161         pass

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\bcolz.pyc in compute_down(expr, data, chunksize, map, **kwargs)
    122 
    123     parts = list(map(curry(compute_chunk, data, chunk, chunk_expr),
--> 124                      data_parts))
    125 
    126     if isinstance(parts[0], np.ndarray):

C:\Anaconda\envs\blaze_test\lib\site-packages\toolz\functoolz.pyc in __call__(self, *args, **kwargs)
    214     def __call__(self, *args, **kwargs):
    215         try:
--> 216             return self._partial(*args, **kwargs)
    217         except TypeError:
    218             # If there was a genuine TypeError

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\bcolz.pyc in compute_chunk(source, chunk, chunk_expr, data_index)
     88 def compute_chunk(source, chunk, chunk_expr, data_index):
     89     part = source[data_index]
---> 90     return compute(chunk_expr, {chunk: part})
     91 
     92 

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469 
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    162 
    163     # 2. Compute from the bottom until there is a data type change
--> 164     expr2, scope2 = bottom_up_until_type_break(expr, scope, **kwargs)
    165 
    166     # 3. Re-optimize data and expressions

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in bottom_up_until_type_break(expr, scope, **kwargs)
    346     #    (this is the bottom part of bottom up)
    347     exprs, new_scopes = zip(*[bottom_up_until_type_break(i, scope, **kwargs)
--> 348                              for i in inputs])
    349 
    350     # 2. Form new (much shallower) expression and new (more computed) scope

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in bottom_up_until_type_break(expr, scope, **kwargs)
    369     try:
    370         return leaf, {leaf: compute_up(new_expr, *_data, scope=new_scope,
--> 371                                        **kwargs)}
    372     except NotImplementedError:
    373         return new_expr, new_scope

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\numpy.pyc in compute_up(sel, x, **kwargs)
    197 @dispatch(Selection, np.ndarray)
    198 def compute_up(sel, x, **kwargs):
--> 199     return x[compute(sel.predicate, {sel._child: x})]
    200 
    201 

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469 
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    191                 "data: %s" % (expr3, scope4))
    192     else:
--> 193         return top_then_bottom_then_top_again_etc(expr3, scope4, **kwargs)
    194 
    195 

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    162 
    163     # 2. Compute from the bottom until there is a data type change
--> 164     expr2, scope2 = bottom_up_until_type_break(expr, scope, **kwargs)
    165 
    166     # 3. Re-optimize data and expressions

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\core.pyc in bottom_up_until_type_break(expr, scope, **kwargs)
    369     try:
    370         return leaf, {leaf: compute_up(new_expr, *_data, scope=new_scope,
--> 371                                        **kwargs)}
    372     except NotImplementedError:
    373         return new_expr, new_scope

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164 
    165         except MDNotImplementedError:

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\numba.pyc in broadcast_numba(t, *data, **kwargs)
    206 def broadcast_numba(t, *data, **kwargs):
    207     try:
--> 208         ufunc = get_numba_ufunc(t)
    209     except TypeError:  # strings and objects aren't supported very well yet
    210         return compute(t, dict(zip(t._leaves(), data)))

C:\Anaconda\envs\blaze_test\lib\site-packages\toolz\functoolz.pyc in memof(*args, **kwargs)
    343             return cache[k]
    344         else:
--> 345             result = func(*args, **kwargs)
    346             cache[k] = result
    347             return result

C:\Anaconda\envs\blaze_test\lib\site-packages\blaze\compute\numba.pyc in _get_numba_ufunc(expr)
    197     func = eval(s, scope)
    198     sig = compute_signature(expr)
--> 199     return numba.vectorize([sig], nopython=True)(func)
    200 
    201 

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\npyufunc\decorators.pyc in wrap(func)
     80         vec = Vectorize(func, **kws)
     81         for fty in ftylist:
---> 82             vec.add(fty)
     83         return vec.build_ufunc()
     84 

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\npyufunc\ufuncbuilder.pyc in add(self, sig, argtypes, restype)
    108         # Do compilation
    109         # Return CompileResult to test
--> 110         cres = self.nb_func.compile(sig)
    111 
    112         args, return_type = sigutils.normalize_signature(sig)

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\npyufunc\ufuncbuilder.pyc in compile(self, sig, locals, **targetoptions)
     59         cres = compiler.compile_extra(typingctx, targetctx, self.py_func,
     60                                       args=args, return_type=return_type,
---> 61                                       flags=flags, locals=locals)
     62 
     63         self.overloads[cres.signature] = cres

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    552     pipeline = Pipeline(typingctx, targetctx, library,
    553                         args, return_type, flags, locals)
--> 554     return pipeline.compile_extra(func)
    555 
    556 

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\compiler.pyc in compile_extra(self, func)
    298                 raise e
    299 
--> 300         return self.compile_bytecode(bc, func_attr=self.func_attr)
    301 
    302     def compile_bytecode(self, bc, lifted=(),

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\compiler.pyc in compile_bytecode(self, bc, lifted, func_attr)
    306         self.lifted = lifted
    307         self.func_attr = func_attr
--> 308         return self._compile_bytecode()
    309 
    310     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES):

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\compiler.pyc in _compile_bytecode(self)
    539 
    540         pm.finalize()
--> 541         return pm.run(self.status)
    542 
    543 

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_151_g071b39e-py2.7-win32.egg\numba\compiler.pyc in run(self, status)
    196                     # No more fallback pipelines?
    197                     if is_final_pipeline:
--> 198                         raise patched_exception
    199                     # Go to next fallback pipeline
    200                     else:

TypingError: Failed at nopython (nopython frontend)
Undeclared ==(int8, str)
File "<string>", line 1
```

bcolz string comparison fails on NYC dataset
I have the following code that fails when performing string comparison against bcolz backend. 

``` python
d = blaze.Data('nyc.bcolz')
blaze.discover(d)
```

```
dshape("""173185091 * {
  medallion: string[32, 'A'],
  hack_license: string[32, 'A'],
  vendor_id: string[3, 'A'],
  rate_code: int64,
  store_and_fwd_flag: string[1, 'A'],
  pickup_datetime: datetime,
  dropoff_datetime: datetime,
  passenger_count: int64,
  trip_time_in_secs: int64,
  trip_distance: float64,
  pickup_longitude: float64,
  pickup_latitude: float64,
  dropoff_longitude: float64,
  dropoff_latitude: float64,
  payment_type: string[3, 'A'],
  fare_amount: float64,
  surcharge: float64,
  mta_tax: float64,
  tip_amount: float64,
  tolls_amount: float64,
  total_amount: float64
  }""")
```

The following query works just fine. Along with any other query that is performing a numeric filtering. 

``` python
d[d.total_amount > 400]
```

But string comparison fails:

``` python
d[d.medallion == '0BD7C8F5BA12B88E0B67BED28BEA73D8']
```

```
TypingError: Failed at nopython (nopython frontend)
Undeclared ==([char x 32], str)
File "<string>", line 1

Out[8]:
Data:       [ ('89D227B655E5C82AECF13C3F540D4CF4', 'BA96DE419E711691B9445D6A6307C170', 'CMT', 1, 'N', 1357053108000000000L, 1357053490000000000L, 4, 382, 1.0, -73.978165, 40.757977000000004, -73.989838, 40.751171, 'CSH', 6.5, 0.0, 0.5, 0.0, 0.0, 7.0)
 ('0BD7C8F5BA12B88E0B67BED28BEA73D8', '9FD8F69F0804BDB5549F40E9DA1BE472', 'CMT', 1, 'N', 1357431515000000000L, 1357431774000000000L, 1, 259, 1.5, -74.006683, 40.731781, -73.994499, 40.750659999999996, 'CSH', 6.0, 0.5, 0.5, 0.0, 0.0, 7.0)
 ('0BD7C8F5BA12B88E0B67BED28BEA73D8', '9FD8F69F0804BDB5549F40E9DA1BE472', 'CMT', 1, 'N', 1357411781000000000L, 1357412063000000000L, 1, 282, 1.1, -74.004707, 40.737770000000005, -74.009834, 40.726002, 'CSH', 5.5, 1.0, 0.5, 0.0, 0.0, 7.0)
 ...,
 ('ABC075C8871353E9F12ADEB5F1E27C2A', '2E24AB48335EDC44EADE1CE29F6BCBF4', 'VTS', 1, '', 1386313020000000000L, 1386313560000000000L, 3, 540, 1.69, -73.972183, 40.794407, -73.972336, 40.796397999999996, 'CRD', 9.0, 0.0, 0.5, 2.7, 0.0, 12.2)
 ('1FB2BF12B504498BC8B7B860294CD372', '03D43975C87C8B5CFBDA1FF33B3AD743', 'VTS', 1, '', 1386313440000000000L, 1386313560000000000L, 1, 120, 0.7, 0.0, 0.0, 0.0, 0.0, 'CRD', 4.0, 0.0, 0.5, 0.8, 0.0, 5.3)
 ('FC2D556EBF3EC3043221010139A16D70', 'FD028AE01E96C2518503E60A463ABAEE', 'VTS', 1, '', 1386313320000000000L, 1386313680000000000L, 1, 360, 1.35, -73.962921, 40.770748, -73.981255, 40.771114000000004, 'CSH', 7.0, 0.0, 0.5, 0.0, 0.0, 7.5)]
Expr:       _1[_1.medallion == '0BD7C8F5BA12B88E0B67BED28BEA73D8']
DataShape:  var * {
  medallion: string[32, 'A'],
  hack_license: string[32, 'A'],
  vendor_id: string[3, 'A'],
  rate_code: int64,
  store_and_fwd_flag: string[1, 'A'],
  pickup_datetime: datetime,
  ...
```

However the same query performed using bcolz interfaces works just fine:

``` python
bz = bcolz.open(rootdir='nyc.bcolz')

qry = bz.where("medallion == '0BD7C8F5BA12B88E0B67BED28BEA73D8'")
lt = [i._asdict() for i in qry]
df = pd.DataFrame(lt)
```

Any idea what's happening here. Does this has something to do with the dtype **medallion: string[32, 'A'],**?? 



Discussion:
@ARF1 What happens when you do

``` python
blaze.compute(d['date'])
```

@cpcloud Ok, there seem to be weird things going on with my system. After restarting python to try out your question: `blaze.compute(d['date'])` works and `blaze.compute(d[['date']])` now works as well. I suspect that I managed to overwrite the variable `d` at some point during my experimentation...

New try, with a clean namespace, the problem reappears with the following code segment:

```
d = blaze.Data(db)
a = d[['date', 'col1', 'col2', 'col3', 'col4']]
b = a[((a.col2 == 'ABC') | 
       (a.col2 == 'DEF') | 
       (a.col2 == 'GHI')) &
      (a.col3 != 2) &
      (a.col4 != 2)]
results = blaze.compute(b)
```

Traceback is identical to the one in the OP.

@ARF1 Can you provide some example data and/or show the contents of `db`?

@cpcloud Sorry this took a while. Attached is a self-contained test-case including full backtrace.

```
Z:\>conda create -n blaze_test -c blaze -c numba pip blaze ipython
...
Linking packages ...
[      COMPLETE      ] |#################################################| 100%
#
# To activate this environment, use:
# > activate blaze_test
#

Z:\>activate blaze_test
Activating environment "blaze_test"...

[blaze_test] Z:\>ipython
Python 2.7.9 |Continuum Analytics, Inc.| (default, Dec 18 2014, 17:00:07) [MSC v
.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import pandas

In [2]: import blaze

In [3]: import bcolz

In [4]: a = pandas.DataFrame({'col1': [1, 2, 3], 'col2': ['ABC', 'DEF', 'GHI']})

In [5]: b = bcolz.ctable.fromdataframe(a)

In [6]: d = blaze.Data(b)

In [7]: blaze.compute(d[((d.col2 == 'ABC') | (d.col2 == 'DEF'))])
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-7-bc7c45079453> in <module>()
----> 1 blaze.compute(d[((d.col2 == 'ABC') | (d.col2 == 'DEF'))])

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\intera
ctive.pyc in compute(expr, **kwargs)
    160         raise ValueError("No data resources found")
    161     else:
--> 162         return compute(expr, resources, **kwargs)
    163
    164

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    157     # 1. See if we have a direct computation path with compute_down
    158     try:
--> 159         return compute_down(expr, *leaf_data, **kwargs)
    160     except NotImplementedError:
    161         pass

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\bcolz.pyc in compute_down(expr, data, chunksize, map, **kwargs)
    126
    127     parts = list(map(curry(compute_chunk, data, chunk, chunk_expr),
--> 128                      data_parts))
    129
    130     if isinstance(parts[0], np.ndarray):

C:\Anaconda\envs\blaze_test\lib\site-packages\toolz\functoolz.pyc in __call__(se
lf, *args, **kwargs)
    214     def __call__(self, *args, **kwargs):
    215         try:
--> 216             return self._partial(*args, **kwargs)
    217         except TypeError:
    218             # If there was a genuine TypeError

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\bcolz.pyc in compute_chunk(source, chunk, chunk_expr, data_index)
     89 def compute_chunk(source, chunk, chunk_expr, data_index):
     90     part = source[data_index]
---> 91     return compute(chunk_expr, {chunk: part})
     92
     93

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    162
    163     # 2. Compute from the bottom until there is a data type change
--> 164     expr2, scope2 = bottom_up_until_type_break(expr, scope, **kwargs)
    165
    166     # 3. Re-optimize data and expressions

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in bottom_up_until_type_break(expr, scope, **kwargs)
    369     try:
    370         return leaf, {leaf: compute_up(new_expr, *_data, scope=new_scope
,
--> 371                                        **kwargs)}
    372     except NotImplementedError:
    373         return new_expr, new_scope

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\numpy.pyc in compute_up(sel, x, **kwargs)
    197 @dispatch(Selection, np.ndarray)
    198 def compute_up(sel, x, **kwargs):
--> 199     return x[compute(sel.predicate, {sel._child: x})]
    200
    201

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in compute(expr, d, **kwargs)
    468         d4 = d3
    469
--> 470     result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    471     if post_compute_:
    472         result = post_compute_(expr3, result, scope=d4)

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in top_then_bottom_then_top_again_etc(expr, scope, **kwargs)
    162
    163     # 2. Compute from the bottom until there is a data type change
--> 164     expr2, scope2 = bottom_up_until_type_break(expr, scope, **kwargs)
    165
    166     # 3. Re-optimize data and expressions

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\core.pyc in bottom_up_until_type_break(expr, scope, **kwargs)
    369     try:
    370         return leaf, {leaf: compute_up(new_expr, *_data, scope=new_scope
,
--> 371                                        **kwargs)}
    372     except NotImplementedError:
    373         return new_expr, new_scope

C:\Anaconda\envs\blaze_test\lib\site-packages\multipledispatch\dispatcher.pyc in
 __call__(self, *args, **kwargs)
    161             self._cache[types] = func
    162         try:
--> 163             return func(*args, **kwargs)
    164
    165         except MDNotImplementedError:

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\numba.pyc in broadcast_numba(t, *data, **kwargs)
    206 def broadcast_numba(t, *data, **kwargs):
    207     try:
--> 208         ufunc = get_numba_ufunc(t)
    209     except TypeError:  # strings and objects aren't supported very well
yet
    210         return compute(t, dict(zip(t._leaves(), data)))

C:\Anaconda\envs\blaze_test\lib\site-packages\toolz\functoolz.pyc in memof(*args
, **kwargs)
    343             return cache[k]
    344         else:
--> 345             result = func(*args, **kwargs)
    346             cache[k] = result
    347             return result

c:\anaconda\envs\blaze_test\lib\site-packages\blaze-0.7.3-py2.7.egg\blaze\comput
e\numba.pyc in _get_numba_ufunc(expr)
    197     func = eval(s, scope)
    198     sig = compute_signature(expr)
--> 199     return numba.vectorize([sig], nopython=True)(func)
    200
    201

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\npyufunc\decorators.pyc in wrap(func)
     80         vec = Vectorize(func, **kws)
     81         for fty in ftylist:
---> 82             vec.add(fty)
     83         return vec.build_ufunc()
     84

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\npyufunc\ufuncbuilder.pyc in add(self, sig, argtypes, restype)
    108         # Do compilation
    109         # Return CompileResult to test
--> 110         cres = self.nb_func.compile(sig)
    111
    112         args, return_type = sigutils.normalize_signature(sig)

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\npyufunc\ufuncbuilder.pyc in compile(self, sig, locals, **targetop
tions)
     59         cres = compiler.compile_extra(typingctx, targetctx, self.py_func
,
     60                                       args=args, return_type=return_type
,
---> 61                                       flags=flags, locals=locals)
     62
     63         self.overloads[cres.signature] = cres

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\compiler.pyc in compile_extra(typingctx, targetctx, func, args, re
turn_type, flags, locals, library)
    552     pipeline = Pipeline(typingctx, targetctx, library,
    553                         args, return_type, flags, locals)
--> 554     return pipeline.compile_extra(func)
    555
    556

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\compiler.pyc in compile_extra(self, func)
    298                 raise e
    299
--> 300         return self.compile_bytecode(bc, func_attr=self.func_attr)
    301
    302     def compile_bytecode(self, bc, lifted=(),

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\compiler.pyc in compile_bytecode(self, bc, lifted, func_attr)
    306         self.lifted = lifted
    307         self.func_attr = func_attr
--> 308         return self._compile_bytecode()
    309
    310     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES
):

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\compiler.pyc in _compile_bytecode(self)
    539
    540         pm.finalize()
--> 541         return pm.run(self.status)
    542
    543

c:\anaconda\envs\blaze_test\lib\site-packages\numba-0.17.0_259_g6c0e096-py2.7-wi
n32.egg\numba\compiler.pyc in run(self, status)
    196                     # No more fallback pipelines?
    197                     if is_final_pipeline:
--> 198                         raise patched_exception
    199                     # Go to next fallback pipeline
    200                     else:

TypingError: Failed at nopython (nopython frontend)
Undeclared ==([char x 3], str)
File "<string>", line 1
```

Note that with earlier versions the same test case works just fine:

```
[sandbox] Z:\>ipython
Python 2.7.9 |Anaconda 2.1.0 (32-bit)| (default, Dec 18 2014, 17:00:07) [MSC v.1
500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %paste
In [1]: import pandas

In [2]: import blaze

In [3]: import bcolz

In [4]: a = pandas.DataFrame({'col1': [1, 2, 3], 'col2': ['ABC', 'DEF', 'GHI']})


In [5]: b = bcolz.ctable.fromdataframe(a)

In [6]: d = blaze.Data(b)

In [7]: blaze.compute(d[((d.col2 == 'ABC') | (d.col2 == 'DEF'))])

## -- End pasted text --
Out[1]:
array([(1L, 'ABC'), (2L, 'DEF')],
      dtype=[('col1', '<i8'), ('col2', 'S3')])

In [2]: quit()

[sandbox] Z:\>conda list blaze
# packages in environment at C:\Anaconda\envs\sandbox:
#
blaze                     0.7.0                np19py27_0

[sandbox] Z:\>conda list numba
# packages in environment at C:\Anaconda\envs\sandbox:
#
numba                     0.16.0               np19py27_0
```

I can replicate the error - just having a look at what's going on in Numba in the failing case.

Some observations:

With the versions of blaze and numba that you mention do work as listed above (numba 0.16.0 and blaze 0.7.0) work for me only on Python 2. On Python 3, I get this traceback:

```
$ python test.py 
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    blaze.compute(e)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/multipledispatch/dispatcher.py", line 163, in __call__
    return func(*args, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/blaze/interactive.py", line 152, in compute
    return compute(expr, resources, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/multipledispatch/dispatcher.py", line 163, in __call__
    return func(*args, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/blaze/compute/core.py", line 464, in compute
    result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/blaze/compute/core.py", line 159, in top_then_bottom_then_top_again_etc
    return compute_down(expr, *leaf_data, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/multipledispatch/dispatcher.py", line 163, in __call__
    return func(*args, **kwargs)
  File "/home/gmarkall/.conda/envs/blaze_test_old/lib/python3.4/site-packages/blaze/compute/bcolz.py", line 139, in compute_down
    "Don't know how to concatenate objects of type %s" % type(parts[0]))
TypeError: Don't know how to concatenate objects of type <class 'numpy.void'>
```

If I look inside `compute_down`, the value of `parts` differs. At bcolz.py:131, In Python 2:

``` python
In [2]: parts[0]
Out[2]:
array([(1, 'ABC'), (2, 'DEF')], 
      dtype=[('col1', '<i8'), ('col2', 'S3')])
```

In Python 3:

``` python
In [1]: parts[0]
Out[1]: (1, b'ABC')
```

As far as I could tell, in Python 2 where it did work, it didn't use Numba for the computation.

@gmarkall I can confirm that I was using python 2.7.9 in the test I mentioned as working.

Since the problem seems to stem from Numba, is there a way to disable Numba in blaze until this issue is resolved? 

Hrm, short term you could shut down expression optimization on numpy expressions.  Running the following code after importing blaze should stop numba from operating on expressions with a single numpy array input.

``` python
from blaze import dispatch, np, Expr

@dispatch(Expr, np.ndarray)
def optimize(expr, data, **kwargs):
    return expr
```

You could also call `compute` explicitly with `optimize=False`.

@gmarkall thoughts on what's happening here?  Should Blaze avoid Numba in the case of string types?  Especially given that we're in nopython mode.

Thanks for the help. The redefinition of the optimize function works. 
(optimize=False does not...)

@mrocklin It looks like Blaze correctly determines the type of the argument of this function:

``` python
lambda col2: (col2 == 'ABC') | (col2 == 'DEF')
```

as `CharSeq(3)` but Numba is typing `'ABC'` and `'DEF'` as `string`, which is a dummy type that doesn't really carry any information about itself, so it's not possible to use in Nopython mode. I hope that this can be improved, and will provide a further update once I have a better idea of what is possible.

It looks like Blaze is trying to roll your predicate `d.medallion = '...'` into a numba ufunc for speed but that Numba doesn't like dealing with fixed length strings.  This is an oversight on the part of Blaze, which should probably not try to optimize in these cases and just rely on straight numpy/pandas (particularly since the selection itself is fairly simple.)

Your immediate problem can be resolved by disabling numba optimization with the following lines

``` python
from blaze import dispatch, Expr, np

@dispatch(Expr, np.ndarray) 
def optimize(expr, data, **kwargs):
    return expr
```

But we'll have to improve this more generally in Blaze.  I've also noticed that the chunklen that blaze uses defaults to whatever is in the bcolz carray which might be small.  If this is less than say, 2**16 performance is likely to be poor.


Resolving patch:
diff --git a/blaze/compute/bcolz.py b/blaze/compute/bcolz.py
--- a/blaze/compute/bcolz.py
+++ b/blaze/compute/bcolz.py
@@ -109,7 +109,7 @@ def compute_down(expr, data, chunksize=None, map=None, **kwargs):
     leaf = expr._leaves()[0]
 
     if chunksize is None:
-        chunksize = get_chunksize(data)
+        chunksize = max(2**16, get_chunksize(data))
 
     # If the bottom expression is a projection or field then want to do
     # compute_up first
diff --git a/blaze/compute/numba.py b/blaze/compute/numba.py
--- a/blaze/compute/numba.py
+++ b/blaze/compute/numba.py
@@ -4,6 +4,7 @@
 
 from .core import compute, optimize
 from ..expr import Expr, Arithmetic, Math, Map, UnaryOp
+from ..expr.strings import isstring
 from ..expr.broadcast import broadcast_collect, Broadcast
 from toolz import memoize
 import datashape
@@ -15,8 +16,15 @@
 
 
 def optimize_ndarray(expr, *data, **kwargs):
-    return broadcast_collect(expr, Broadcastable=Broadcastable,
-                             WantToBroadcast=Broadcastable)
+    dshapes = expr._leaves()
+    for leaf in expr._leaves():
+        if (isstring(leaf.dshape.measure) or
+            isinstance(leaf.dshape.measure, datashape.Record) and
+            any(isstring(dt) for dt in leaf.dshape.measure.types)):
+            return expr
+        else:
+            return broadcast_collect(expr, Broadcastable=Broadcastable,
+                                     WantToBroadcast=Broadcastable)
 
 
 for i in range(1, 11):


Test patch:
diff --git a/blaze/compute/tests/test_numpy_compute.py b/blaze/compute/tests/test_numpy_compute.py
--- a/blaze/compute/tests/test_numpy_compute.py
+++ b/blaze/compute/tests/test_numpy_compute.py
@@ -410,3 +410,11 @@ def test_join():
     expr = join(t, c, 'name')
     result = compute(expr, {t: x, c: cities})
     assert (b'Alice', 1, 100, 'LA') in into(list, result)
+
+
+def test_query_with_strings():
+    b = np.array([('a', 1), ('b', 2), ('c', 3)],
+                 dtype=[('x', 'S1'), ('y', 'i4')])
+
+    s = symbol('s', discover(b))
+    assert compute(s[s.x == b'b'], b).tolist() == [(b'b', 2)]