Code Sample,
In [4]: df = pd.DataFrame({'series': pd.Series(range(3))})
In [5]: df["name"] = "abc"
In [6]: df_copy = df.copy()
In [7]: df.series.loc[2] = None
In [8]: df
Out[8]:
series name
0 0.0 abc
1 1.0 abc
2 NaN abc
In [9]: df_copy
Out[9]:
series name
0 0 abc
1 1 abc
2 2 abc
In [10]: df[df.isnull()] = df_copy
#or
#df.where(-df.isnull(), df_copy, inplace=True)
#basically it's doing that at the end
Problem description
Pandas throws a TypeError:
Traceback (most recent call last):
File ".../test_replace.py", line 8, in <module>
df[df.isnull()] = df_copy
File ".../anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 2516, in __setitem__
self._setitem_frame(key, value)
File ".../anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 2552, in _setitem_frame
self._check_inplace_setting(value)
File ".../anaconda/lib/python2.7/site-packages/pandas/core/generic.py", line 3738, in _check_inplace_setting
raise TypeError('Cannot do inplace boolean setting on '
TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value
I understand that in-place setting doesn't like to work with the mixed types, but I can't see a reason why it shouldn't work in this case and maybe check in "_check_inplace_setting()" is a bit too tight ?
Expected Output
same as with df.where(-df.isnull(), df_copy)
In [12]: df.where(-df.isnull(), df_copy)
Out[12]:
series name
0 0.0 abc
1 1.0 abc
2 2.0 abc
Comment From: jreback
duplicate of #15613. the current mechanism is not very robust for multi dtype setting. welcome for you to have a look.