Skip to content
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Performance

.. _whatsnew_0160.performance:

- Fixed a severe performance regression for ``.loc`` indexing with an array or list (:issue:9126:).

Bug Fixes
~~~~~~~~~
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,9 +1275,8 @@ def _has_valid_type(self, key, axis):
if isinstance(key, tuple) and isinstance(ax, MultiIndex):
return True

# require at least 1 element in the index
idx = _ensure_index(key)
if len(idx) and not idx.isin(ax).any():
# TODO: don't check the entire key unless necessary
if len(key) and np.all(ax.get_indexer_for(key) < 0):

raise KeyError("None of [%s] are in the [%s]" %
(key, self.obj._get_axis_name(axis)))
Expand Down
27 changes: 27 additions & 0 deletions vb_suite/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,30 @@

frame_iloc_big = Benchmark('df.iloc[:100,0]', setup,
start_date=datetime(2013, 1, 1))

#----------------------------------------------------------------------
# basic tests for [], .loc[], .iloc[] and .ix[]

setup = common_setup + """
s = Series(np.random.rand(1000000))
"""

series_getitem_scalar = Benchmark("s[800000]", setup)
series_getitem_slice = Benchmark("s[:800000]", setup)
series_getitem_list_like = Benchmark("s[[800000]]", setup)
series_getitem_array = Benchmark("s[np.arange(10000)]", setup)

series_loc_scalar = Benchmark("s.loc[800000]", setup)
series_loc_slice = Benchmark("s.loc[:800000]", setup)
series_loc_list_like = Benchmark("s.loc[[800000]]", setup)
series_loc_array = Benchmark("s.loc[np.arange(10000)]", setup)

series_iloc_scalar = Benchmark("s.loc[800000]", setup)
series_iloc_slice = Benchmark("s.loc[:800000]", setup)
series_iloc_list_like = Benchmark("s.loc[[800000]]", setup)
series_iloc_array = Benchmark("s.loc[np.arange(10000)]", setup)

series_ix_scalar = Benchmark("s.ix[800000]", setup)
series_ix_slice = Benchmark("s.ix[:800000]", setup)
series_ix_list_like = Benchmark("s.ix[[800000]]", setup)
series_ix_array = Benchmark("s.ix[np.arange(10000)]", setup)