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

Merged
merged 1 commit into from Mar 31, 2013

2 participants

@jreback

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

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

@jreback jreback BUG: GH3216 Upcast when needed to DataFrame when setitem with indexer
ENH: On a mixed DataFrame, allow setting with indexers with ndarray/DataFrame on rhs
749d911
@jreback jreback merged commit d09fff8 into pydata:master Mar 31, 2013
@y-p

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

@jreback

huh ?

@y-p

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

ahh didn't know that
will do

@y-p

no worries.

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