You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> import pandas as pd
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4], 'C': [5, 6], 'D': [7, 8]})
>>> pd.melt(df, id_vars=('A', 'B'), value_vars=('C', 'D'))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-ef146f73874a> in <module>()
----> 1 pd.melt(df, id_vars=('A', 'B'), value_vars=('C', 'D'))
/Users/josh/env/analysis/lib/python3.5/site-packages/pandas/core/reshape.py in melt(frame, id_vars, value_vars, var_name, value_name, col_level)
766 if not isinstance(value_vars, (tuple, list, np.ndarray)):
767 value_vars = [value_vars]
--> 768 frame = frame.ix[:, id_vars + value_vars]
769 else:
770 frame = frame.copy()
TypeError: can only concatenate list (not "tuple") to list
Problem description
The documentation says that id_vars and value_vars can be tuples, lists, or ndarrays, but it doesn't work if value_vars is a tuple. The function works as expected if value_vars is given as a list.
The value_vars argument of melt is now cast to list like the
id_vars argument.
closespandas-dev#15348
Author: Joshua Bradt <[email protected]>
Author: Joshua Bradt <[email protected]>
Closespandas-dev#15351 from jbradt/fix-melt and squashes the following commits:
a2f2510 [Joshua Bradt] Changed to tm.assertRaisesRegexp for Python 2 compat.
3038f64 [Joshua Bradt] Merge remote-tracking branch 'upstream/master' into fix-melt
e907135 [Joshua Bradt] Split test into two parts
20159c1 [Joshua Bradt] Changed exception classes to ValueError.
129d531 [Joshua Bradt] Moved binary operators to satisfy flake8
70d7256 [Joshua Bradt] Merge branch 'master' into fix-melt
455a310 [Joshua Bradt] Tested types when using MultiIndex to ensure they are lists.
7406222 [Joshua Bradt] Fixed formatting. Added comment with issue number to test.
d4c5da3 [Joshua Bradt] Improved type checking and tests. Added whatsnew note.
33728de [Joshua Bradt] BUG: Fixed handling of non-list value_vars in melt
Code Sample
Problem description
The documentation says that
id_vars
andvalue_vars
can be tuples, lists, or ndarrays, but it doesn't work ifvalue_vars
is a tuple. The function works as expected ifvalue_vars
is given as a list.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 26.1.1
Cython: 0.24.1
numpy: 1.12.0
scipy: 0.18.0
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: