We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BUG: boolean query evaluation
http://stackoverflow.com/questions/21414959/querying-a-single-row-dataframe-with-anded-conditionals/21415119#21415119

cc @cpcloud 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pandas/computation/align.py`
Content:
```
1 """Core eval alignment algorithms
2 """
3 
4 import warnings
5 from functools import partial, wraps
6 from pandas.compat import zip, range
7 
8 import numpy as np
9 
10 import pandas as pd
11 from pandas import compat
12 import pandas.core.common as com
13 
14 
15 def _align_core_single_unary_op(term):
16     if isinstance(term.value, np.ndarray):
17         typ = partial(np.asanyarray, dtype=term.value.dtype)
18     else:
19         typ = type(term.value)
20     ret = typ,
21 
22     if not hasattr(term.value, 'axes'):
23         ret += None,
24     else:
25         ret += _zip_axes_from_type(typ, term.value.axes),
26     return ret
27 
28 
29 def _zip_axes_from_type(typ, new_axes):
30     axes = {}
31     for ax_ind, ax_name in compat.iteritems(typ._AXIS_NAMES):
32         axes[ax_name] = new_axes[ax_ind]
33     return axes
34 
35 
36 def _maybe_promote_shape(values, naxes):
37     # test to see if we have an array else leave since must be a number
38     if not isinstance(values, np.ndarray):
39         return values
40 
41     ndims = values.ndim
42     if ndims > naxes:
43         raise AssertionError('cannot have more dims than axes, '
44                              '{0} > {1}'.format(ndims, naxes))
45     if ndims == naxes:
46         return values
47 
48     ndim, nax = range(ndims), range(naxes)
49 
50     axes_slice = [slice(None)] * naxes
51 
52     # set difference of numaxes and ndims
53     slices = list(set(nax) - set(ndim))
54 
55     if ndims == naxes:
56         if slices:
57             raise AssertionError('slices should be empty if ndims == naxes '
58                                  '{0}'.format(slices))
59     else:
60         if not slices:
61             raise AssertionError('slices should NOT be empty if ndim != naxes '
62                                  '{0}'.format(slices))
63 
64     for sl in slices:
65         axes_slice[sl] = np.newaxis
66 
67     return values[tuple(axes_slice)]
68 
69 
70 def _any_pandas_objects(terms):
71     """Check a sequence of terms for instances of PandasObject."""
72     return any(isinstance(term.value, pd.core.generic.PandasObject)
73                for term in terms)
74 
75 
76 def _filter_special_cases(f):
77     @wraps(f)
78     def wrapper(terms):
79         # single unary operand
80         if len(terms) == 1:
81             return _align_core_single_unary_op(terms[0])
82 
83         term_values = (term.value for term in terms)
84         # only scalars or indexes
85         if all(isinstance(term.value, pd.Index) or term.isscalar for term in
86                terms):
87             return np.result_type(*term_values), None
88 
89         # single element ndarrays
90         all_has_size = all(hasattr(term.value, 'size') for term in terms)
91         if all_has_size and all(term.value.size == 1 for term in terms):
92             return np.result_type(*term_values), None
93 
94         # no pandas objects
95         if not _any_pandas_objects(terms):
96             return np.result_type(*term_values), None
97 
98         return f(terms)
99     return wrapper
100 
101 
102 @_filter_special_cases
103 def _align_core(terms):
104     term_index = [i for i, term in enumerate(terms)
105                   if hasattr(term.value, 'axes')]
106     term_dims = [terms[i].value.ndim for i in term_index]
107     ndims = pd.Series(dict(zip(term_index, term_dims)))
108 
109     # initial axes are the axes of the largest-axis'd term
110     biggest = terms[ndims.idxmax()].value
111     typ = biggest._constructor
112     axes = biggest.axes
113     naxes = len(axes)
114     gt_than_one_axis = naxes > 1
115 
116     for value in (terms[i].value for i in term_index):
117         is_series = isinstance(value, pd.Series)
118         is_series_and_gt_one_axis = is_series and gt_than_one_axis
119 
120         for axis, items in enumerate(value.axes):
121             if is_series_and_gt_one_axis:
122                 ax, itm = naxes - 1, value.index
123             else:
124                 ax, itm = axis, items
125 
126             if not axes[ax].is_(itm):
127                 axes[ax] = axes[ax].join(itm, how='outer')
128 
129     for i, ndim in compat.iteritems(ndims):
130         for axis, items in zip(range(ndim), axes):
131             ti = terms[i].value
132 
133             if hasattr(ti, 'reindex_axis'):
134                 transpose = isinstance(ti, pd.Series) and naxes > 1
135                 reindexer = axes[naxes - 1] if transpose else items
136 
137                 term_axis_size = len(ti.axes[axis])
138                 reindexer_size = len(reindexer)
139 
140                 ordm = np.log10(abs(reindexer_size - term_axis_size))
141                 if ordm >= 1 and reindexer_size >= 10000:
142                     warnings.warn('Alignment difference on axis {0} is larger '
143                                   'than an order of magnitude on term {1!r}, '
144                                   'by more than {2:.4g}; performance may '
145                                   'suffer'.format(axis, terms[i].name, ordm),
146                                   category=pd.io.common.PerformanceWarning)
147 
148                 if transpose:
149                     f = partial(ti.reindex, index=reindexer, copy=False)
150                 else:
151                     f = partial(ti.reindex_axis, reindexer, axis=axis,
152                                 copy=False)
153 
154                 # need  to fill if we have a bool dtype/array
155                 if (isinstance(ti, (np.ndarray, pd.Series))
156                         and ti.dtype == object
157                         and pd.lib.is_bool_array(ti.values)):
158                     r = f(fill_value=True)
159                 else:
160                     r = f()
161 
162                 terms[i].update(r)
163 
164         res = _maybe_promote_shape(terms[i].value.T if transpose else
165                                    terms[i].value, naxes)
166         res = res.T if transpose else res
167 
168         try:
169             v = res.values
170         except AttributeError:
171             v = res
172         terms[i].update(v)
173 
174     return typ, _zip_axes_from_type(typ, axes)
175 
176 
177 def _filter_terms(flat):
178     # numeric literals
179     literals = frozenset(filter(lambda x: isinstance(x, Constant), flat))
180 
181     # these are strings which are variable names
182     names = frozenset(flat) - literals
183 
184     # literals are not names and names are not literals, so intersection should
185     # be empty
186     if literals & names:
187         raise ValueError('literals cannot be names and names cannot be '
188                          'literals')
189     return names, literals
190 
191 
192 def _align(terms):
193     """Align a set of terms"""
194     try:
195         # flatten the parse tree (a nested list, really)
196         terms = list(com.flatten(terms))
197     except TypeError:
198         # can't iterate so it must just be a constant or single variable
199         if isinstance(terms.value, pd.core.generic.NDFrame):
200             typ = type(terms.value)
201             return typ, _zip_axes_from_type(typ, terms.value.axes)
202         return np.result_type(terms.type), None
203 
204     # if all resolved variables are numeric scalars
205     if all(term.isscalar for term in terms):
206         return np.result_type(*(term.value for term in terms)).type, None
207 
208     # perform the main alignment
209     typ, axes = _align_core(terms)
210     return typ, axes
211 
212 
213 def _reconstruct_object(typ, obj, axes, dtype):
214     """Reconstruct an object given its type, raw value, and possibly empty
215     (None) axes.
216 
217     Parameters
218     ----------
219     typ : object
220         A type
221     obj : object
222         The value to use in the type constructor
223     axes : dict
224         The axes to use to construct the resulting pandas object
225 
226     Returns
227     -------
228     ret : typ
229         An object of type ``typ`` with the value `obj` and possible axes
230         `axes`.
231     """
232     try:
233         typ = typ.type
234     except AttributeError:
235         pass
236 
237     try:
238         res_t = np.result_type(obj.dtype, dtype)
239     except AttributeError:
240         res_t = dtype
241 
242     if (not isinstance(typ, partial) and
243             issubclass(typ, pd.core.generic.PandasObject)):
244         return typ(obj, dtype=res_t, **axes)
245 
246     # special case for pathological things like ~True/~False
247     if hasattr(res_t, 'type') and typ == np.bool_ and res_t != np.bool_:
248         ret_value = res_t.type(obj)
249     else:
250         ret_value = typ(obj).astype(res_t)
251 
252     try:
253         ret = ret_value.item()
254     except (ValueError, IndexError):
255         # XXX: we catch IndexError to absorb a
256         # regression in numpy 1.7.0
257         # fixed by numpy/numpy@04b89c63
258         ret = ret_value
259     return ret
260
```
--- 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/pandas/computation/align.py b/pandas/computation/align.py
--- a/pandas/computation/align.py
+++ b/pandas/computation/align.py
@@ -81,16 +81,12 @@
             return _align_core_single_unary_op(terms[0])
 
         term_values = (term.value for term in terms)
+
         # only scalars or indexes
         if all(isinstance(term.value, pd.Index) or term.isscalar for term in
                terms):
             return np.result_type(*term_values), None
 
-        # single element ndarrays
-        all_has_size = all(hasattr(term.value, 'size') for term in terms)
-        if all_has_size and all(term.value.size == 1 for term in terms):
-            return np.result_type(*term_values), None
-
         # no pandas objects
         if not _any_pandas_objects(terms):
             return np.result_type(*term_values), None

{"golden_diff": "diff --git a/pandas/computation/align.py b/pandas/computation/align.py\n--- a/pandas/computation/align.py\n+++ b/pandas/computation/align.py\n@@ -81,16 +81,12 @@\n             return _align_core_single_unary_op(terms[0])\n \n         term_values = (term.value for term in terms)\n+\n         # only scalars or indexes\n         if all(isinstance(term.value, pd.Index) or term.isscalar for term in\n                terms):\n             return np.result_type(*term_values), None\n \n-        # single element ndarrays\n-        all_has_size = all(hasattr(term.value, 'size') for term in terms)\n-        if all_has_size and all(term.value.size == 1 for term in terms):\n-            return np.result_type(*term_values), None\n-\n         # no pandas objects\n         if not _any_pandas_objects(terms):\n             return np.result_type(*term_values), None\n", "issue": "BUG: boolean query evaluation\nhttp://stackoverflow.com/questions/21414959/querying-a-single-row-dataframe-with-anded-conditionals/21415119#21415119\n\ncc @cpcloud \n\n", "before_files": [{"content": "\"\"\"Core eval alignment algorithms\n\"\"\"\n\nimport warnings\nfrom functools import partial, wraps\nfrom pandas.compat import zip, range\n\nimport numpy as np\n\nimport pandas as pd\nfrom pandas import compat\nimport pandas.core.common as com\n\n\ndef _align_core_single_unary_op(term):\n    if isinstance(term.value, np.ndarray):\n        typ = partial(np.asanyarray, dtype=term.value.dtype)\n    else:\n        typ = type(term.value)\n    ret = typ,\n\n    if not hasattr(term.value, 'axes'):\n        ret += None,\n    else:\n        ret += _zip_axes_from_type(typ, term.value.axes),\n    return ret\n\n\ndef _zip_axes_from_type(typ, new_axes):\n    axes = {}\n    for ax_ind, ax_name in compat.iteritems(typ._AXIS_NAMES):\n        axes[ax_name] = new_axes[ax_ind]\n    return axes\n\n\ndef _maybe_promote_shape(values, naxes):\n    # test to see if we have an array else leave since must be a number\n    if not isinstance(values, np.ndarray):\n        return values\n\n    ndims = values.ndim\n    if ndims > naxes:\n        raise AssertionError('cannot have more dims than axes, '\n                             '{0} > {1}'.format(ndims, naxes))\n    if ndims == naxes:\n        return values\n\n    ndim, nax = range(ndims), range(naxes)\n\n    axes_slice = [slice(None)] * naxes\n\n    # set difference of numaxes and ndims\n    slices = list(set(nax) - set(ndim))\n\n    if ndims == naxes:\n        if slices:\n            raise AssertionError('slices should be empty if ndims == naxes '\n                                 '{0}'.format(slices))\n    else:\n        if not slices:\n            raise AssertionError('slices should NOT be empty if ndim != naxes '\n                                 '{0}'.format(slices))\n\n    for sl in slices:\n        axes_slice[sl] = np.newaxis\n\n    return values[tuple(axes_slice)]\n\n\ndef _any_pandas_objects(terms):\n    \"\"\"Check a sequence of terms for instances of PandasObject.\"\"\"\n    return any(isinstance(term.value, pd.core.generic.PandasObject)\n               for term in terms)\n\n\ndef _filter_special_cases(f):\n    @wraps(f)\n    def wrapper(terms):\n        # single unary operand\n        if len(terms) == 1:\n            return _align_core_single_unary_op(terms[0])\n\n        term_values = (term.value for term in terms)\n        # only scalars or indexes\n        if all(isinstance(term.value, pd.Index) or term.isscalar for term in\n               terms):\n            return np.result_type(*term_values), None\n\n        # single element ndarrays\n        all_has_size = all(hasattr(term.value, 'size') for term in terms)\n        if all_has_size and all(term.value.size == 1 for term in terms):\n            return np.result_type(*term_values), None\n\n        # no pandas objects\n        if not _any_pandas_objects(terms):\n            return np.result_type(*term_values), None\n\n        return f(terms)\n    return wrapper\n\n\n@_filter_special_cases\ndef _align_core(terms):\n    term_index = [i for i, term in enumerate(terms)\n                  if hasattr(term.value, 'axes')]\n    term_dims = [terms[i].value.ndim for i in term_index]\n    ndims = pd.Series(dict(zip(term_index, term_dims)))\n\n    # initial axes are the axes of the largest-axis'd term\n    biggest = terms[ndims.idxmax()].value\n    typ = biggest._constructor\n    axes = biggest.axes\n    naxes = len(axes)\n    gt_than_one_axis = naxes > 1\n\n    for value in (terms[i].value for i in term_index):\n        is_series = isinstance(value, pd.Series)\n        is_series_and_gt_one_axis = is_series and gt_than_one_axis\n\n        for axis, items in enumerate(value.axes):\n            if is_series_and_gt_one_axis:\n                ax, itm = naxes - 1, value.index\n            else:\n                ax, itm = axis, items\n\n            if not axes[ax].is_(itm):\n                axes[ax] = axes[ax].join(itm, how='outer')\n\n    for i, ndim in compat.iteritems(ndims):\n        for axis, items in zip(range(ndim), axes):\n            ti = terms[i].value\n\n            if hasattr(ti, 'reindex_axis'):\n                transpose = isinstance(ti, pd.Series) and naxes > 1\n                reindexer = axes[naxes - 1] if transpose else items\n\n                term_axis_size = len(ti.axes[axis])\n                reindexer_size = len(reindexer)\n\n                ordm = np.log10(abs(reindexer_size - term_axis_size))\n                if ordm >= 1 and reindexer_size >= 10000:\n                    warnings.warn('Alignment difference on axis {0} is larger '\n                                  'than an order of magnitude on term {1!r}, '\n                                  'by more than {2:.4g}; performance may '\n                                  'suffer'.format(axis, terms[i].name, ordm),\n                                  category=pd.io.common.PerformanceWarning)\n\n                if transpose:\n                    f = partial(ti.reindex, index=reindexer, copy=False)\n                else:\n                    f = partial(ti.reindex_axis, reindexer, axis=axis,\n                                copy=False)\n\n                # need  to fill if we have a bool dtype/array\n                if (isinstance(ti, (np.ndarray, pd.Series))\n                        and ti.dtype == object\n                        and pd.lib.is_bool_array(ti.values)):\n                    r = f(fill_value=True)\n                else:\n                    r = f()\n\n                terms[i].update(r)\n\n        res = _maybe_promote_shape(terms[i].value.T if transpose else\n                                   terms[i].value, naxes)\n        res = res.T if transpose else res\n\n        try:\n            v = res.values\n        except AttributeError:\n            v = res\n        terms[i].update(v)\n\n    return typ, _zip_axes_from_type(typ, axes)\n\n\ndef _filter_terms(flat):\n    # numeric literals\n    literals = frozenset(filter(lambda x: isinstance(x, Constant), flat))\n\n    # these are strings which are variable names\n    names = frozenset(flat) - literals\n\n    # literals are not names and names are not literals, so intersection should\n    # be empty\n    if literals & names:\n        raise ValueError('literals cannot be names and names cannot be '\n                         'literals')\n    return names, literals\n\n\ndef _align(terms):\n    \"\"\"Align a set of terms\"\"\"\n    try:\n        # flatten the parse tree (a nested list, really)\n        terms = list(com.flatten(terms))\n    except TypeError:\n        # can't iterate so it must just be a constant or single variable\n        if isinstance(terms.value, pd.core.generic.NDFrame):\n            typ = type(terms.value)\n            return typ, _zip_axes_from_type(typ, terms.value.axes)\n        return np.result_type(terms.type), None\n\n    # if all resolved variables are numeric scalars\n    if all(term.isscalar for term in terms):\n        return np.result_type(*(term.value for term in terms)).type, None\n\n    # perform the main alignment\n    typ, axes = _align_core(terms)\n    return typ, axes\n\n\ndef _reconstruct_object(typ, obj, axes, dtype):\n    \"\"\"Reconstruct an object given its type, raw value, and possibly empty\n    (None) axes.\n\n    Parameters\n    ----------\n    typ : object\n        A type\n    obj : object\n        The value to use in the type constructor\n    axes : dict\n        The axes to use to construct the resulting pandas object\n\n    Returns\n    -------\n    ret : typ\n        An object of type ``typ`` with the value `obj` and possible axes\n        `axes`.\n    \"\"\"\n    try:\n        typ = typ.type\n    except AttributeError:\n        pass\n\n    try:\n        res_t = np.result_type(obj.dtype, dtype)\n    except AttributeError:\n        res_t = dtype\n\n    if (not isinstance(typ, partial) and\n            issubclass(typ, pd.core.generic.PandasObject)):\n        return typ(obj, dtype=res_t, **axes)\n\n    # special case for pathological things like ~True/~False\n    if hasattr(res_t, 'type') and typ == np.bool_ and res_t != np.bool_:\n        ret_value = res_t.type(obj)\n    else:\n        ret_value = typ(obj).astype(res_t)\n\n    try:\n        ret = ret_value.item()\n    except (ValueError, IndexError):\n        # XXX: we catch IndexError to absorb a\n        # regression in numpy 1.7.0\n        # fixed by numpy/numpy@04b89c63\n        ret = ret_value\n    return ret\n", "path": "pandas/computation/align.py"}], "after_files": [{"content": "\"\"\"Core eval alignment algorithms\n\"\"\"\n\nimport warnings\nfrom functools import partial, wraps\nfrom pandas.compat import zip, range\n\nimport numpy as np\n\nimport pandas as pd\nfrom pandas import compat\nimport pandas.core.common as com\n\n\ndef _align_core_single_unary_op(term):\n    if isinstance(term.value, np.ndarray):\n        typ = partial(np.asanyarray, dtype=term.value.dtype)\n    else:\n        typ = type(term.value)\n    ret = typ,\n\n    if not hasattr(term.value, 'axes'):\n        ret += None,\n    else:\n        ret += _zip_axes_from_type(typ, term.value.axes),\n    return ret\n\n\ndef _zip_axes_from_type(typ, new_axes):\n    axes = {}\n    for ax_ind, ax_name in compat.iteritems(typ._AXIS_NAMES):\n        axes[ax_name] = new_axes[ax_ind]\n    return axes\n\n\ndef _maybe_promote_shape(values, naxes):\n    # test to see if we have an array else leave since must be a number\n    if not isinstance(values, np.ndarray):\n        return values\n\n    ndims = values.ndim\n    if ndims > naxes:\n        raise AssertionError('cannot have more dims than axes, '\n                             '{0} > {1}'.format(ndims, naxes))\n    if ndims == naxes:\n        return values\n\n    ndim, nax = range(ndims), range(naxes)\n\n    axes_slice = [slice(None)] * naxes\n\n    # set difference of numaxes and ndims\n    slices = list(set(nax) - set(ndim))\n\n    if ndims == naxes:\n        if slices:\n            raise AssertionError('slices should be empty if ndims == naxes '\n                                 '{0}'.format(slices))\n    else:\n        if not slices:\n            raise AssertionError('slices should NOT be empty if ndim != naxes '\n                                 '{0}'.format(slices))\n\n    for sl in slices:\n        axes_slice[sl] = np.newaxis\n\n    return values[tuple(axes_slice)]\n\n\ndef _any_pandas_objects(terms):\n    \"\"\"Check a sequence of terms for instances of PandasObject.\"\"\"\n    return any(isinstance(term.value, pd.core.generic.PandasObject)\n               for term in terms)\n\n\ndef _filter_special_cases(f):\n    @wraps(f)\n    def wrapper(terms):\n        # single unary operand\n        if len(terms) == 1:\n            return _align_core_single_unary_op(terms[0])\n\n        term_values = (term.value for term in terms)\n\n        # only scalars or indexes\n        if all(isinstance(term.value, pd.Index) or term.isscalar for term in\n               terms):\n            return np.result_type(*term_values), None\n\n        # no pandas objects\n        if not _any_pandas_objects(terms):\n            return np.result_type(*term_values), None\n\n        return f(terms)\n    return wrapper\n\n\n@_filter_special_cases\ndef _align_core(terms):\n    term_index = [i for i, term in enumerate(terms)\n                  if hasattr(term.value, 'axes')]\n    term_dims = [terms[i].value.ndim for i in term_index]\n    ndims = pd.Series(dict(zip(term_index, term_dims)))\n\n    # initial axes are the axes of the largest-axis'd term\n    biggest = terms[ndims.idxmax()].value\n    typ = biggest._constructor\n    axes = biggest.axes\n    naxes = len(axes)\n    gt_than_one_axis = naxes > 1\n\n    for value in (terms[i].value for i in term_index):\n        is_series = isinstance(value, pd.Series)\n        is_series_and_gt_one_axis = is_series and gt_than_one_axis\n\n        for axis, items in enumerate(value.axes):\n            if is_series_and_gt_one_axis:\n                ax, itm = naxes - 1, value.index\n            else:\n                ax, itm = axis, items\n\n            if not axes[ax].is_(itm):\n                axes[ax] = axes[ax].join(itm, how='outer')\n\n    for i, ndim in compat.iteritems(ndims):\n        for axis, items in zip(range(ndim), axes):\n            ti = terms[i].value\n\n            if hasattr(ti, 'reindex_axis'):\n                transpose = isinstance(ti, pd.Series) and naxes > 1\n                reindexer = axes[naxes - 1] if transpose else items\n\n                term_axis_size = len(ti.axes[axis])\n                reindexer_size = len(reindexer)\n\n                ordm = np.log10(abs(reindexer_size - term_axis_size))\n                if ordm >= 1 and reindexer_size >= 10000:\n                    warnings.warn('Alignment difference on axis {0} is larger '\n                                  'than an order of magnitude on term {1!r}, '\n                                  'by more than {2:.4g}; performance may '\n                                  'suffer'.format(axis, terms[i].name, ordm),\n                                  category=pd.io.common.PerformanceWarning)\n\n                if transpose:\n                    f = partial(ti.reindex, index=reindexer, copy=False)\n                else:\n                    f = partial(ti.reindex_axis, reindexer, axis=axis,\n                                copy=False)\n\n                # need  to fill if we have a bool dtype/array\n                if (isinstance(ti, (np.ndarray, pd.Series))\n                        and ti.dtype == object\n                        and pd.lib.is_bool_array(ti.values)):\n                    r = f(fill_value=True)\n                else:\n                    r = f()\n\n                terms[i].update(r)\n\n        res = _maybe_promote_shape(terms[i].value.T if transpose else\n                                   terms[i].value, naxes)\n        res = res.T if transpose else res\n\n        try:\n            v = res.values\n        except AttributeError:\n            v = res\n        terms[i].update(v)\n\n    return typ, _zip_axes_from_type(typ, axes)\n\n\ndef _filter_terms(flat):\n    # numeric literals\n    literals = frozenset(filter(lambda x: isinstance(x, Constant), flat))\n\n    # these are strings which are variable names\n    names = frozenset(flat) - literals\n\n    # literals are not names and names are not literals, so intersection should\n    # be empty\n    if literals & names:\n        raise ValueError('literals cannot be names and names cannot be '\n                         'literals')\n    return names, literals\n\n\ndef _align(terms):\n    \"\"\"Align a set of terms\"\"\"\n    try:\n        # flatten the parse tree (a nested list, really)\n        terms = list(com.flatten(terms))\n    except TypeError:\n        # can't iterate so it must just be a constant or single variable\n        if isinstance(terms.value, pd.core.generic.NDFrame):\n            typ = type(terms.value)\n            return typ, _zip_axes_from_type(typ, terms.value.axes)\n        return np.result_type(terms.type), None\n\n    # if all resolved variables are numeric scalars\n    if all(term.isscalar for term in terms):\n        return np.result_type(*(term.value for term in terms)).type, None\n\n    # perform the main alignment\n    typ, axes = _align_core(terms)\n    return typ, axes\n\n\ndef _reconstruct_object(typ, obj, axes, dtype):\n    \"\"\"Reconstruct an object given its type, raw value, and possibly empty\n    (None) axes.\n\n    Parameters\n    ----------\n    typ : object\n        A type\n    obj : object\n        The value to use in the type constructor\n    axes : dict\n        The axes to use to construct the resulting pandas object\n\n    Returns\n    -------\n    ret : typ\n        An object of type ``typ`` with the value `obj` and possible axes\n        `axes`.\n    \"\"\"\n    try:\n        typ = typ.type\n    except AttributeError:\n        pass\n\n    try:\n        res_t = np.result_type(obj.dtype, dtype)\n    except AttributeError:\n        res_t = dtype\n\n    if (not isinstance(typ, partial) and\n            issubclass(typ, pd.core.generic.PandasObject)):\n        return typ(obj, dtype=res_t, **axes)\n\n    # special case for pathological things like ~True/~False\n    if hasattr(res_t, 'type') and typ == np.bool_ and res_t != np.bool_:\n        ret_value = res_t.type(obj)\n    else:\n        ret_value = typ(obj).astype(res_t)\n\n    try:\n        ret = ret_value.item()\n    except (ValueError, IndexError):\n        # XXX: we catch IndexError to absorb a\n        # regression in numpy 1.7.0\n        # fixed by numpy/numpy@04b89c63\n        ret = ret_value\n    return ret\n", "path": "pandas/computation/align.py"}]}