BUG: concat with dataframes heterogeneous in length and tuple keys #14438

Closed
dubourg opened this Issue Oct 17, 2016 · 1 comment

Comments

Projects
None yet
4 participants
Contributor

dubourg commented Oct 17, 2016

A small, complete example of the issue

import numpy as np
import pandas as pd
df1 = pd.DataFrame(np.random.rand(4).reshape((2, 2)), columns=list('AB'))
df2 = pd.DataFrame(np.random.rand(6).reshape((3, 2)), columns=list('AB'))
print(pd.concat([df1, df2], keys=[('bee', 'bah'), ('bee', 'bouh')], names=['zig', 'zag', None]))

Expected Output (works w/ 0.18.1)

                   A         B
zig zag                       
bee bah  0  0.689411  0.364650
         1  0.143786  0.415858
    bouh 0  0.557942  0.646434
         1  0.551938  0.695175
         2  0.991975  0.880451

0.19 raises

/path/to/lib/python3.4/site-packages/pandas/tools/merge.py in _make_concat_multiindex(indexes, keys, levels, names)
   1673         else:
   1674             codes, categories = _factorize_from_iterable(concat_index)
-> 1675             levels.append(categories)
   1676             label_list.append(codes)
   1677 

AttributeError: 'tuple' object has no attribute 'append'

Output of pd.show_versions()

## INSTALLED VERSIONS

commit: None
python: 3.4.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-74-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG:
LOCALE: None.None

pandas: 0.19.0
nose: None
pip: 8.1.2
setuptools: 27.2.0
Cython: None
numpy: 1.11.2
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

chris-b1 added the Bug label Oct 19, 2016

chris-b1 added this to the Next Major Release milestone Oct 19, 2016

chris-b1 changed the title from concat with dataframes heterogeneous in length and tuple keys raises AttributeError: 'tuple' object has no attribute 'append' (as of pandas 0.19) to BUG: concat with dataframes heterogeneous in length and tuple keys Oct 19, 2016

Contributor

chris-b1 commented Oct 19, 2016

Thanks for the report, PRs welcome!

@dubourg dubourg added a commit to dubourg/pandas that referenced this issue Oct 19, 2016

@dubourg dubourg Type codes and categories as lists instead of tuples in _factorize_fr…
…om_iterables (fixes #14438)
57a2ec8

@jreback jreback modified the milestone: 0.19.1, Next Major Release Oct 20, 2016

jreback closed this in #14449 Oct 20, 2016

@tworec tworec added a commit to RTBHOUSE/pandas that referenced this issue Oct 21, 2016

@dubourg @tworec dubourg + tworec Type codes and categories as lists instead of tuples in _factorize_fr…
…om_iterables (fixes #14438) (#14449)
7cc286d

@jorisvandenbossche jorisvandenbossche added a commit that referenced this issue Nov 1, 2016

@dubourg @jorisvandenbossche dubourg + jorisvandenbossche [Backport #14449] Type codes and categories as lists instead of tuple…
…s in _factorize_from_iterables (fixes #14438)

(cherry picked from commit 0b6946b)
9857248

@amolkahat amolkahat added a commit to amolkahat/pandas that referenced this issue Nov 26, 2016

@dubourg @amolkahat dubourg + amolkahat Type codes and categories as lists instead of tuples in _factorize_fr…
…om_iterables (fixes #14438) (#14449)
c2d5c66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment