{"action":"opened","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/9653","labels_url":"https://api.github.com/repos/pydata/pandas/issues/9653/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/9653/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/9653/events","html_url":"https://github.com/pydata/pandas/issues/9653","id":61297235,"number":9653,"title":"Inconsistencies in DataFrame construction with MultiIndex.from_tuples","user":{"login":"brianthelion","id":296082,"avatar_url":"https://avatars.githubusercontent.com/u/296082?v=3","gravatar_id":"","url":"https://api.github.com/users/brianthelion","html_url":"https://github.com/brianthelion","followers_url":"https://api.github.com/users/brianthelion/followers","following_url":"https://api.github.com/users/brianthelion/following{/other_user}","gists_url":"https://api.github.com/users/brianthelion/gists{/gist_id}","starred_url":"https://api.github.com/users/brianthelion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianthelion/subscriptions","organizations_url":"https://api.github.com/users/brianthelion/orgs","repos_url":"https://api.github.com/users/brianthelion/repos","events_url":"https://api.github.com/users/brianthelion/events{/privacy}","received_events_url":"https://api.github.com/users/brianthelion/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-13T23:34:55Z","updated_at":"2015-03-13T23:34:55Z","closed_at":null,"body":"It's not clear to me that this is a \"bug\" per se, but it's certainly not intuitive behavior. My thought was that these two methods would result in identical DataFrames.\r\n\r\n```python\r\nimport numpy as np\r\nimport pandas as pd\r\n\r\ndef multiindex_version_1(data):\r\n    n, m = data.shape\r\n    tuples = [('a', _n) for _n in xrange(m-1)] + [('b', )]\r\n    columns = pd.MultiIndex.from_tuples(tuples)\r\n    df = pd.DataFrame(data, columns=columns)\r\n    return df\r\n    \r\ndef multiindex_version_2(data):\r\n    n, m = data.shape\r\n    tuples = [('a', _n) for _n in xrange(m-1)]\r\n    columns = pd.MultiIndex.from_tuples(tuples)\r\n    df = pd.DataFrame(data[:, :(m-1)], columns=columns)\r\n    df['b'] = data[:, m-1]\r\n    return df\r\n\r\ndef test_goofy_multiindexing():\r\n    shape = (10, 4)\r\n    data = np.random.rand(*shape)\r\n    df1 = multiindex_version_1(data)\r\n    print \"============= version_1 =============\"\r\n    print df1\r\n    df2 = multiindex_version_2(data)\r\n    print \"============= version_2 =============\"\r\n    print df2\r\n    assert (df1==df2).all()\r\n```\r\nNote the NaN immediately below.\r\n```\r\n============= version_1 =============\r\n          a                             b\r\n          0         1         2       NaN\r\n0  0.742381  0.981698  0.976639  0.212344\r\n1  0.278328  0.188071  0.320450  0.236994\r\n2  0.543064  0.786865  0.065103  0.233676\r\n3  0.084130  0.081981  0.295404  0.113241\r\n4  0.025517  0.522754  0.238385  0.284278\r\n5  0.263382  0.176789  0.289079  0.472668\r\n6  0.933632  0.328850  0.006974  0.191654\r\n7  0.557348  0.313619  0.582076  0.897741\r\n8  0.271253  0.815123  0.113981  0.787208\r\n9  0.595073  0.887483  0.350284  0.815767\r\n============= version_2 =============\r\n          a                             b\r\n          0         1         2          \r\n0  0.742381  0.981698  0.976639  0.212344\r\n1  0.278328  0.188071  0.320450  0.236994\r\n2  0.543064  0.786865  0.065103  0.233676\r\n3  0.084130  0.081981  0.295404  0.113241\r\n4  0.025517  0.522754  0.238385  0.284278\r\n5  0.263382  0.176789  0.289079  0.472668\r\n6  0.933632  0.328850  0.006974  0.191654\r\n7  0.557348  0.313619  0.582076  0.897741\r\n8  0.271253  0.815123  0.113981  0.787208\r\n9  0.595073  0.887483  0.350284  0.815767\r\nE\r\n======================================================================\r\nERROR: test_scatter.test_goofy_multiindexing\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python2.7/dist-packages/nose/case.py\", line 197, in runTest\r\n    self.test(*self.arg)\r\n  File \"/home/br/test/test_scatter.py\", line 99, in test_goofy_multiindexing\r\n    assert (df1==df2).all()\r\n  File \"/home/br/.virtualenvs/cloudlab/local/lib/python2.7/site-packages/pandas/core/ops.py\", line 912, in f\r\n    return self._compare_frame(other, func, str_rep)\r\n  File \"/home/br/.virtualenvs/cloudlab/local/lib/python2.7/site-packages/pandas/core/frame.py\", line 3136, in _compare_frame\r\n    raise ValueError('Can only compare identically-labeled '\r\nValueError: Can only compare identically-labeled DataFrame objects\r\n-------------------- >> begin captured logging << --------------------\r\nrospy.topics: INFO: topicmanager initialized\r\n--------------------- >> end captured logging << ---------------------\r\n\r\n----------------------------------------------------------------------\r\nRan 1 test in 0.010s\r\n\r\nFAILED (errors=1)\r\n```"}}