Skip to content
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

PERF: pass through to numpy validation for iloc setitem #32257

Merged
merged 9 commits into from
Feb 27, 2020

Conversation

jbrockmendel
Copy link
Member

We lose a little bit of ground on the range and slice (not really sure why), pick up a bigger amount of ground on list or ndarray.

In [3]: ser = pd.Series(range(10**5))                                                                                      
In [4]: key = range(100, 200) 
In [5]: key2 = list(key)
In [6]: key3 = slice(100, 200)                                                                                             
In [7]: key4 = np.array(key2)                                                                                                 

In [16]: %timeit ser.iloc[key] = 1
56.3 µs ± 1.19 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- master
62.9 µs ± 1.77 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- PR

In [17]: %timeit ser.iloc[key2] = 1
95.6 µs ± 2.69 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- master
55.6 µs ± 922 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- PR

In [20]: %timeit ser.iloc[key3] = 1
49 µs ± 756 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- master
50.6 µs ± 1.01 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- PR

In [21]: %timeit ser.iloc[key4] = 1
71.6 µs ± 1.98 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- master
45.7 µs ± 427 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- PR

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance labels Feb 26, 2020
@jreback jreback added this to the 1.1 milestone Feb 26, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. minor nit

if isinstance(key, tuple):
if len(key) > self.ndim:
# TODO: we could let this fall through if we are OK
# with having numpy raise IndexError("too many indices for array")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be ok i think

@@ -27,6 +27,9 @@

from pandas.tseries.offsets import BDay

# We pass through a TypeError raised by numpy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. you used iloc_msg in the other function (non-private); i would make these more verbose

slice_exception_msg

@jbrockmendel
Copy link
Member Author

Removed the tuple length validation, picked up on the order of a microsecond compared to the posts from the OP.

@jreback jreback merged commit 922f932 into pandas-dev:master Feb 27, 2020
@jreback
Copy link
Contributor

jreback commented Feb 27, 2020

thanks

@jbrockmendel jbrockmendel deleted the yaks-_get_setitem_indexer branch February 27, 2020 14:55
roberthdevries pushed a commit to roberthdevries/pandas that referenced this pull request Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants