BUG: unexpected assign by a single-element list · Issue #19474 · pandas-dev/pandas (original) (raw)

import pandas as pd df = pd.DataFrame([[1,2,3], [4,5,6]],columns=["A", "B", "C"]) df.loc[0, ["C"]] = ["Z"] df A B C 0 1 2 [Z] 1 4 5 6

At first I thought this happened because the method is not idiomatic. But I noticed a method with numpy.array is showed in here (section:Setting)
df.loc[:,'D'] = np.array([5] * len(df))
So I reported this just in case. Sorry but I cannot judge whether my method is completely non-idiomatic
or whether latest reported bugs contains mine.

#more elements : as I expected
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
df.loc[0, ["A", "B"]] = ["X", "Y"]
df
   A  B  C
0  X  Y  3
1  4  5  6

#axis=0 : as I expected
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
df.loc[[0], "C"] = ["Z"]
df
   A  B  C
0  1  2  Z
1  4  5  6

#using numpy.array : NOT as I expected
import numpy as np
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=["A", "B", "C"])
s = np.array(["Z"])
df.loc[0, ["C"]] = s
df
   A  B    C
0  1  2  [Z]
1  4  5    6

#assign instead a list containing int : as I expected
df = pd.DataFrame([[1,2,3], [4,5,6]],columns=["A", "B", "C"])
df.loc[0, ["C"]] = [9]
df
   A  B  C
0  1  2  9
1  4  5  6

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.2.5
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None