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

Indexing gives view of data but copy of axis #6

Open
kwgoodman opened this issue Jul 24, 2010 · 2 comments
Open

Indexing gives view of data but copy of axis #6

kwgoodman opened this issue Jul 24, 2010 · 2 comments
Labels

Comments

@kwgoodman
Copy link
Contributor

Non-fancy indexing of a numpy array returns a view. A view of the data of a datarray is returned:

>> x = DataArray([[1,2],[3,4]], [('row', ['r1', 'r2']), ('col', ['c1', 'c2'])])
>> y = x[0]

>> y[0] = 9
>> x[0,0]
   9

But a copy of the axes is returned:

>> y.axes[0].ticks[0] = 'X'
>> x.axes[0].ticks[0]
   'r1'

Is that what we want?

@rspeer
Copy link
Contributor

rspeer commented Jul 27, 2010

I see two ways to fix this:

  • Make ticks immutable
  • Store ticks in a list subclass with copy-on-write semantics

Copying the ticks every time would be far too slow for NumPy.

@kwgoodman
Copy link
Contributor Author

Ticks are one example. But the Axis object contains other things like index and name. If we went the immutable route, then the entire Axis object would have to be immutable. At the moment we can't do that since we have to be able to change the index, for example, for slicing.

pandas went the immutable route. One advantage is that the output of a binary operation can return a view of the Axis since axes (Index in pandas) is immutable. That's fast.

But I like to be able to change the ticks in my own use.

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

No branches or pull requests

2 participants