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

Assignment by Attribute has Odd Behavior #6160

Closed
cancan101 opened this issue Jan 29, 2014 · 4 comments
Closed

Assignment by Attribute has Odd Behavior #6160

cancan101 opened this issue Jan 29, 2014 · 4 comments
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@cancan101
Copy link
Contributor

When assigning to a column in a DataFrame, If I assign an existing column, the assignment works:

In [36]: df = pd.DataFrame({'a':[1,2,12], 'b':['a','b','a']})
In [37]: df.b = df.a
In [38]: print df
    a   b
0   1   1
1   2   2
2  12  12

[3 rows x 2 columns]

but assigning to a new column fails silently:

In [40]:df = pd.DataFrame({'a':[1,2,12], 'b':['a','b','a']})
In [41]:df.c = df.a
In [42]:print df
    a  b
0   1  a
1   2  b
2  12  a

[3 rows x 2 columns]
@jreback
Copy link
Contributor

jreback commented Jan 29, 2014

see as #5904
(prob best to issue a warning if their is a name clash)

you are assigning not a column here, but just an attribute

e.g. people do this df.name = 'foo' this does not create a column nor should it

you can make a case for what you are suggesting to work , but the attribute access is really geting only (unless its a reassignment).

I personally think we should bank the reassignment actually.

@cancan101
Copy link
Contributor Author

I would be fine not allowing this at all. What confuses me is that I can use it for reassignment, but then if I forget and try to use for assignment, it just fails without telling me.

@jreback
Copy link
Contributor

jreback commented Jan 29, 2014

yeh...I don't know when the reassignment was allowed...

try taking it out and see what breaks

I don't think its a big deal to break the API...but let's see

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 9, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@TomAugspurger
Copy link
Contributor

Closing in favor of #7175 (warn on setting)

@TomAugspurger TomAugspurger modified the milestones: No action, Next Major Release Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

3 participants