Skip to content

PERF: fix performance for series slices (even more) #6372

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
Feb 16, 2014
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
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Improvements to existing features
- ``plot(legend='reverse')`` will now reverse the order of legend labels for most plot kinds.
(:issue:`6014`)
- Allow multi-index slicers (:issue:`6134`, :issue:`4036`, :issue:`3057`, :issue:`2598`, :issue:`5641`)
- improve performance of slice indexing on Series with string keys (:issue:`6341`)
- improve performance of slice indexing on Series with string keys (:issue:`6341`, :issue:`6372`)
- implement joining a single-level indexed DataFrame on a matching column of a multi-indexed DataFrame (:issue:`3662`)
- Performance improvement in indexing into a multi-indexed Series (:issue:`5567`)
- Testing statements updated to use specialized asserts (:issue: `6175`)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Enhancements
and parse accordingly. (:issue:`6223`)
- ``plot(legend='reverse')`` will now reverse the order of legend labels for
most plot kinds. (:issue:`6014`)
- improve performance of slice indexing on Series with string keys (:issue:`6341`)
- improve performance of slice indexing on Series with string keys (:issue:`6341`, :issue:`6372`)
- Hexagonal bin plots from ``DataFrame.plot`` with ``kind='hexbin'`` (:issue:`5478`)
- Joining a singly-indexed DataFrame with a multi-indexed DataFrame (:issue:`3662`)

Expand Down
20 changes: 1 addition & 19 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ def _slice(self, slobj, axis=0, raise_on_error=False, typ=None):
if raise_on_error:
_check_slice_bounds(slobj, self.values)
slobj = self.index._convert_slice_indexer(slobj, typ=typ or 'getitem')
return self._constructor(self.values[slobj],
index=self.index[slobj]).__finalize__(self)
return self._get_values(slobj)

def __getitem__(self, key):
try:
Expand Down Expand Up @@ -679,23 +678,6 @@ def _set_values(self, key, value):
# help out SparseSeries
_get_val_at = ndarray.__getitem__

def __getslice__(self, i, j):
if i < 0:
i = 0
if j < 0:
j = 0
slobj = slice(i, j)
return self._slice(slobj)

def __setslice__(self, i, j, value):
"""Set slice equal to given value(s)"""
if i < 0:
i = 0
if j < 0:
j = 0
slobj = slice(i, j)
return self.__setitem__(slobj, value)

def repeat(self, reps):
"""
See ndarray.repeat
Expand Down
13 changes: 11 additions & 2 deletions vb_suite/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@
index = tm.makeStringIndex(1000000)
s = Series(np.random.rand(1000000), index=index)
"""
series_getitem_slice = Benchmark("s[:800000]", setup,
name="series_getitem_slice")
series_getitem_pos_slice = Benchmark("s[:800000]", setup,
name="series_getitem_pos_slice")


setup = common_setup + """
index = tm.makeStringIndex(1000000)
s = Series(np.random.rand(1000000), index=index)
lbl = s.index[800000]
"""
series_getitem_label_slice = Benchmark("s[:lbl]", setup,
name="series_getitem_label_slice")


#----------------------------------------------------------------------
Expand Down