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

Set column slices using an ndarray view of the underlying data #3020

Merged
merged 2 commits into from Oct 8, 2014

Conversation

taldcroft
Copy link
Member

As discussed in #2994, in Python 2 setting a table Column slice does not go via __setitem__, but instead via __setslice__. Unless this method is overridden in the subclass then it ends up falling through to __array_finalize__, which is quite slow. This PR improves the speed by an order of magnitude or more for:

In [1]: from astropy.table import Column
In [2]: c = Column([1,2], name='a')
In [3]: timeit c[:] = 2
100000 loops, best of 3: 2.39 µs per loop

@embray
Copy link
Member

embray commented Oct 7, 2014

Ack, I wish I'd remembered this sooner and saved a lot of trouble. I've had to use this workaround before but I'm slowly forgetting all the Python 2-isms :(

@taldcroft
Copy link
Member Author

BTW, no new tests because slicing is well tested already in Table.

@mhvk
Copy link
Contributor

mhvk commented Oct 8, 2014

@taldcroft - OK, thanks for adding that. The only change I would make is add the PR number to the relevant entry I had already made in CHANGES.rst for #2994. With that, this is ready to go.

taldcroft added a commit that referenced this pull request Oct 8, 2014
Set column slices using an ndarray view of the underlying data
@taldcroft taldcroft merged commit 1f9dc67 into astropy:master Oct 8, 2014
@taldcroft taldcroft deleted the table-set-slice branch October 8, 2014 00:49
@embray
Copy link
Member

embray commented Oct 8, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants