Skip to content

PERF: perf enhancements in indexing/query/eval #5590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/computation/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def _align_core(terms):
f = partial(ti.reindex_axis, reindexer, axis=axis,
copy=False)

if pd.lib.is_bool_array(ti.values):
# need to fill if we have a bool dtype/array
if isinstance(ti, (np.ndarray, pd.Series)) and ti.dtype == object and pd.lib.is_bool_array(ti.values):
r = f(fill_value=True)
else:
r = f()
Expand Down
2 changes: 2 additions & 0 deletions pandas/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def update(self, level=None):
while sl >= 0:
frame = frame.f_back
sl -= 1
if frame is None:
break
frames.append(frame)
for f in frames[::-1]:
self.locals.update(f.f_locals)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,9 +3061,9 @@ def combine_first(self, other):
Examples
--------
a's values prioritized, use values from b to fill holes:

>>> a.combine_first(b)


Returns
-------
Expand Down Expand Up @@ -3623,7 +3623,7 @@ def join(self, other, on=None, how='left', lsuffix='', rsuffix='',
how : {'left', 'right', 'outer', 'inner'}
How to handle indexes of the two objects. Default: 'left'
for joining on index, None otherwise

* left: use calling frame's index
* right: use input frame's index
* outer: form union of indexes
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def take(self, indices, axis=0, convert=True):
new_data = self._data.reindex_axis(new_items, indexer=indices,
axis=0)
else:
new_data = self._data.take(indices, axis=baxis)
new_data = self._data.take(indices, axis=baxis, verify=convert)
return self._constructor(new_data)\
._setitem_copy(True)\
.__finalize__(self)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
if isinstance(indexer, slice):
return self._slice(indexer, axis=axis, typ='iloc')
else:
return self.obj.take(indexer, axis=axis)
return self.obj.take(indexer, axis=axis, convert=False)


class _IXIndexer(_NDFrameIndexer):
Expand Down Expand Up @@ -1038,7 +1038,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
if isinstance(indexer, slice):
return self._slice(indexer, axis=axis, typ='iloc')
else:
return self.obj.take(indexer, axis=axis)
return self.obj.take(indexer, axis=axis, convert=False)


class _LocIndexer(_LocationIndexer):
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
return self._slice(slice_obj, axis=axis, raise_on_error=True,
typ='iloc')
else:
return self.obj.take(slice_obj, axis=axis)
return self.obj.take(slice_obj, axis=axis, convert=False)

def _getitem_axis(self, key, axis=0):

Expand Down
7 changes: 3 additions & 4 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3247,10 +3247,9 @@ def take(self, indexer, new_index=None, axis=1, verify=True):

if verify:
indexer = _maybe_convert_indices(indexer, n)

if ((indexer == -1) | (indexer >= n)).any():
raise Exception('Indices must be nonzero and less than '
'the axis length')
if ((indexer == -1) | (indexer >= n)).any():
raise Exception('Indices must be nonzero and less than '
'the axis length')

new_axes = list(self.axes)
if new_index is None:
Expand Down
11 changes: 11 additions & 0 deletions vb_suite/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@

query_datetime_index = Benchmark("df.query('index < ts')",
index_setup, start_date=datetime(2013, 9, 27))

setup = setup + """
N = 1000000
df = DataFrame({'a': np.random.randn(N)})
min_val = df['a'].min()
max_val = df['a'].max()
"""

query_with_boolean_selection = Benchmark("df.query('(a >= min_val) & (a <= max_val)')",
index_setup, start_date=datetime(2013, 9, 27))