Skip to content

Fix TimedeltaIndex constructor fastpath when name is set #10026

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
May 4, 2015

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Apr 30, 2015

Fixes #10025

@shoyer shoyer added this to the 0.16.1 milestone Apr 30, 2015
@shoyer shoyer added the Timedelta Timedelta data type label Apr 30, 2015
@shoyer
Copy link
Member Author

shoyer commented Apr 30, 2015

For the record, I don't think it is actually a good idea to return an existing object from an index constructor. This leads to weird things like:

new_idx = pd.Index(old_idx)
new_index.name = 'foo'
# also sets old_idx.name!

We should preserve the old data and hashtable, if possible, but not everything on an Index object is immutable (name/names is the main exception).

@jreback
Copy link
Contributor

jreback commented Apr 30, 2015

you are setting the name directly, use set_names to get a new object

In [24]: i = Index(range(5),name='foo')

In [25]: i2 = Index(i,name='bar')

In [26]: i3 = i2.set_names('baz')

In [27]: i.name
Out[27]: 'foo'

In [28]: i2.name
Out[28]: 'bar'

In [29]: i3.name
Out[29]: 'baz'

@shoyer
Copy link
Member Author

shoyer commented Apr 30, 2015

@jreback do you really think it is a good idea for the Index constructor to return the same object that was passed in? I agree that set_names is cleaner here...

@jreback
Copy link
Contributor

jreback commented Apr 30, 2015

@shoyer its prob IS a bug that it is doing that. I think that it should be a shallow copy always. See what the other indexes do. Certainly no tests for this type of aliasing I'll bet.

jreback added a commit that referenced this pull request May 4, 2015
Fix TimedeltaIndex constructor fastpath when name is set
@jreback jreback merged commit 867461d into pandas-dev:master May 4, 2015
@jreback
Copy link
Contributor

jreback commented May 4, 2015

thanks!

@shoyer shoyer deleted the fix-tdi-name branch May 4, 2015 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Index constructor does not set name when given a TimedeltaIndex as data
2 participants