Skip to content

BUG: GH3216 Upcast when needed to DataFrame when setitem with indexer #3219

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
Mar 31, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Mar 29, 2013

closes #3216

BUG: GH3216 Upcast when needed to DataFrame when setitem with indexer

The following would raise previously

In [8]: df = pd.DataFrame([{"a": 1}, {"a": 3, "b": 2}])
In [9]: df['c'] = np.nan
In [10]: df.ix[0,'c'] = 'foo'

In [11]: df
Out[11]: 
   a   b    c
0  1 NaN  foo
1  3   2  NaN

In [12]: df.dtypes
Out[12]: 
a      int64
b    float64
c     object
dtype: object

ENH: On a mixed DataFrame, allow setting with indexers with
ndarray/DataFrame on rhs (this was disallowed in the code previously)

In [8]: df = DataFrame([[1,2,'foo'],[3,4,'bar']],columns=['A','B','C'])
In [9]: df2 = df.copy()
In [10]: df2.ix[:,['A','B']] = df.ix[:,['A','B']]+0.5
In [11]: df2
Out[11]: 
     A    B    C
0  1.5  2.5  foo
1  3.5  4.5  bar

In [12]: df2.dtypes
Out[12]: 
A    float64
B    float64
C     object
dtype: object

In [13]: df.dtypes
Out[13]: 
A     int64
B     int64
C    object
dtype: object

@jreback
Copy link
Contributor Author

jreback commented Mar 29, 2013

@wesm this cleans up some of the setitem_indexer code (still a bit spaghetti but lots of cases to handle)....

ENH: On a mixed DataFrame, allow setting with indexers with ndarray/DataFrame on rhs
jreback added a commit that referenced this pull request Mar 31, 2013
BUG: GH3216 Upcast when needed to DataFrame when setitem with indexer
@jreback jreback merged commit d09fff8 into pandas-dev:master Mar 31, 2013
@ghost
Copy link

ghost commented Mar 31, 2013

Yo jeff, one blank line between commit message subject and body. I thank you.

@jreback
Copy link
Contributor Author

jreback commented Mar 31, 2013

huh ?

@ghost
Copy link

ghost commented Mar 31, 2013

When you write your commit messages, please insert a blank line between the first, subject, line
and the rest of the commit message. it confuses all kinds of git tools, as well as git log.

@jreback
Copy link
Contributor Author

jreback commented Mar 31, 2013

ahh didn't know that
will do

@ghost
Copy link

ghost commented Mar 31, 2013

no worries.

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

Successfully merging this pull request may close these issues.

BUG: non-numeric asignment to numeric column not upcasting
1 participant