Skip to content

MultiIndex.from_arrays() does not check lenghts #13599

Closed
@toobaz

Description

@toobaz

Code Sample, a copy-pastable example if possible

In [2]: pd.MultiIndex.from_arrays([[1,2,3], ['a', 'b']])
Out[2]: 
MultiIndex(levels=[[1, 2, 3], ['a', 'b']],
           labels=[[0, 1, 2], [0, 1]])

In [3]: pd.MultiIndex.from_arrays([[1,2,3], ['a', 'b']]).values
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-65e6fa14e07f> in <module>()
----> 1 pd.MultiIndex.from_arrays([[1,2,3], ['a', 'b']]).values

/home/nobackup/repo/pandas/pandas/indexes/multi.py in values(self)
    552             values.append(taken)
    553 
--> 554         self._tuples = lib.fast_zip(values)
    555         return self._tuples
    556 

/home/nobackup/repo/pandas/pandas/lib.pyx in pandas.lib.fast_zip (pandas/lib.c:11131)()
    587         it = <flatiter> PyArray_IterNew(arr)
    588         if len(arr) != n:
--> 589             raise ValueError('all arrays must be same length')
    590 
    591         for i in range(n):

ValueError: all arrays must be same length

Expected Output

The first previous command should already raise an error.

output of pd.show_versions()


In [4]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: a63bd12529ff309d957d714825b1753d0e02b7fa
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.5.0-2-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8

pandas: 0.18.1+174.ga63bd12
nose: 1.3.7
pip: 1.5.6
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.8.0.dev0+111ddc0
xarray: None
IPython: 5.0.0.dev
sphinx: 1.3.1
patsy: 0.3.0-dev
dateutil: 2.2
pytz: 2012c
blosc: None
bottleneck: 1.1.0dev
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: None
xlrd: 0.9.4
xlwt: 1.1.2
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.0
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.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