question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MultiIndex.from_arrays() does not check lenghts

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Jul 10, 2016

@sahildua2305 see contributing docs here

things tagged a ‘Difficulty Novice’ are generally pretty straightforward (like this issue)

0reactions
sahildua2305commented, Jul 10, 2016

Accessible now. Thanks once again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.MultiIndex — pandas 1.5.2 documentation
A multi-level, or hierarchical, index object for pandas objects. Parameters. levelssequence of arrays. The unique labels for each level. codessequence of arrays.
Read more >
Generate MultiIndex DataFrame at different length
MultiIndex.from_product() , I got similar results, that first two index are in a group, third one separated. Since product won't ...
Read more >
How to Fix: Length of values does not match length of index
This tutorial explains how to fix the following error in Python: valueerror: length of values does not match length of index.
Read more >
Source code for databricks.koalas.indexes.multi
See Also -------- MultiIndex.from_arrays : Convert list of arrays to MultiIndex. ... Calling this method does not change the ordering of the values....
Read more >
Hierarchical Indexing | Python Data Science Handbook
This produces the desired result, but is not as clean (or as efficient for large ... Our tuple-based indexing is essentially a rudimentary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found