Skip to content

Setting DataFrame of Python objects and MultiIndex columns wth single-element NDFrame inserts list #14592

Closed
@toobaz

Description

@toobaz

A small, complete example of the issue

In [2]: t = pd.DataFrame('a', index=range(2),
                              columns=pd.MultiIndex.from_product([range(2), range(2)]))

In [3]: t.loc[0, [(0,1)]] = t.loc[0, [(0,1)]]

In [4]: t
Out[4]: 
   0       1   
   0    1  0  1
0  a  [a]  a  a
1  a    a  a  a

The same happens when providing, rather than a list of indices, a mask with only one True value.

The above line is an useless example, but this is a problem in in-place operations.

I suspect the fix should not be very complicated, given that everything works smoothly if we have numbers rather than Python objects (the bug instead arises both if we assign a cell of a numbers-only DF to a cell of a DF of objects, and if we do the opposite)

Expected Output

Just the original t.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 7a2bcb6
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8

pandas: 0.19.0+67.g7a2bcb6.dirty
nose: 1.3.7
pip: 8.1.2
setuptools: 28.0.0
Cython: 0.23.4
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.8.0.dev0+f80669e
xarray: None
IPython: 5.1.0.dev
sphinx: 1.4.8
patsy: 0.3.0-dev
dateutil: 2.5.3
pytz: 2015.7
blosc: None
bottleneck: 1.2.0dev
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.3
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: None
bs4: 4.5.1
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.2
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: 0.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions