{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/14291","repository_url":"https://api.github.com/repos/pydata/pandas","labels_url":"https://api.github.com/repos/pydata/pandas/issues/14291/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/14291/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/14291/events","html_url":"https://github.com/pydata/pandas/issues/14291","id":178886132,"number":14291,"title":"BUG: DataFrame.insert with allow_duplicates=True fails when already duplicates present","user":{"login":"mbochk","id":15201622,"avatar_url":"https://avatars.githubusercontent.com/u/15201622?v=3","gravatar_id":"","url":"https://api.github.com/users/mbochk","html_url":"https://github.com/mbochk","followers_url":"https://api.github.com/users/mbochk/followers","following_url":"https://api.github.com/users/mbochk/following{/other_user}","gists_url":"https://api.github.com/users/mbochk/gists{/gist_id}","starred_url":"https://api.github.com/users/mbochk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbochk/subscriptions","organizations_url":"https://api.github.com/users/mbochk/orgs","repos_url":"https://api.github.com/users/mbochk/repos","events_url":"https://api.github.com/users/mbochk/events{/privacy}","received_events_url":"https://api.github.com/users/mbochk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pydata/pandas/labels/Bug","name":"Bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-23T14:04:17Z","updated_at":"2016-10-04T03:02:43Z","closed_at":null,"body":"upon DataFrame.insert option allow_duplicates works, but only only once.\r\nWhen i have 2 columns with same name, additon of third throws\r\n\r\n> ValueError: Wrong number of items passed 2, placement implies 1\r\n\r\n#### Code Sample, a copy-pastable example if possible\r\n\r\n```\r\na = pd.DataFrame()\r\na.insert(0, \"qwe\", [1,2,3,4], allow_duplicates=True)\r\na.insert(0, \"qwe\", [1,2,3,4], allow_duplicates=True)\r\na.insert(0, \"qwe\", [1,2,3,4], allow_duplicates=True)\r\n```\r\n\r\n#### Expected Output\r\n   zxc  qwe  qwe\r\n0    1    1    1\r\n1    2    2    2\r\n2    3    3    3\r\n3    4    4    4\r\n\r\n#### output of ``pd.show_versions()``\r\n\r\n<details>\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 2.7.12.final.0\r\npython-bits: 64\r\nOS: Windows\r\nOS-release: 7\r\nmachine: AMD64\r\nprocessor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: ru_RU\r\n\r\npandas: 0.18.1\r\nnose: 1.3.7\r\npip: 8.1.2\r\nsetuptools: 25.1.6\r\nCython: 0.24.1\r\nnumpy: 1.11.1\r\nscipy: 0.18.0\r\nstatsmodels: 0.6.1\r\nxarray: None\r\nIPython: 5.1.0\r\nsphinx: 1.4.6\r\npatsy: 0.4.1\r\ndateutil: 2.5.3\r\npytz: 2016.6.1\r\nblosc: None\r\nbottleneck: 1.0.0\r\ntables: 3.2.2\r\nnumexpr: 2.6.1\r\nmatplotlib: 1.5.3\r\nopenpyxl: 2.3.2\r\nxlrd: 1.0.0\r\nxlwt: 1.1.2\r\nxlsxwriter: 0.9.2\r\nlxml: 3.6.4\r\nbs4: 4.4.1\r\nhtml5lib: None\r\nhttplib2: None\r\napiclient: None\r\nsqlalchemy: 1.0.13\r\npymysql: 0.7.6.None\r\npsycopg2: None\r\njinja2: 2.8\r\nboto: 2.40.0\r\npandas_datareader: None\r\n<\\details>"},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/251284080","html_url":"https://github.com/pydata/pandas/issues/14291#issuecomment-251284080","issue_url":"https://api.github.com/repos/pydata/pandas/issues/14291","id":251284080,"user":{"login":"shawnheide","id":7305354,"avatar_url":"https://avatars.githubusercontent.com/u/7305354?v=3","gravatar_id":"","url":"https://api.github.com/users/shawnheide","html_url":"https://github.com/shawnheide","followers_url":"https://api.github.com/users/shawnheide/followers","following_url":"https://api.github.com/users/shawnheide/following{/other_user}","gists_url":"https://api.github.com/users/shawnheide/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnheide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnheide/subscriptions","organizations_url":"https://api.github.com/users/shawnheide/orgs","repos_url":"https://api.github.com/users/shawnheide/repos","events_url":"https://api.github.com/users/shawnheide/events{/privacy}","received_events_url":"https://api.github.com/users/shawnheide/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T03:02:43Z","updated_at":"2016-10-04T03:02:43Z","body":"I looked into this and discovered that the problem is in frame.py, in the _sanitize_column method. Here's the relevant code:\r\n\r\n``` python\r\n# broadcast across multiple columns if necessary\r\nif key in self.columns and value.ndim == 1:\r\n    if (not self.columns.is_unique or\r\n            isinstance(self.columns, MultiIndex)):\r\n        existing_piece = self[key]\r\n        if isinstance(existing_piece, DataFrame):\r\n            value = np.tile(value, (len(existing_piece.columns), 1))\r\n```\r\n\r\nOn the third time `insert` is called, the `existing_piece` is a 2d array consisting of the previous values. I'm not sure how to fix this though as I don't understand why the values are being broadcast in the first place. Any thoughts?"}}
{"actor":{"display_login":"shawnheide"}}