{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/21149","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21149/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21149/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21149/events","html_url":"https://github.com/pandas-dev/pandas/issues/21149","id":324875635,"number":21149,"title":"(Assuming we don't want to disallow 1-level MultiIndexes), stop identifying MultiIndex by nlevels == 1","user":{"login":"toobaz","id":1224492,"avatar_url":"https://avatars1.githubusercontent.com/u/1224492?v=4","gravatar_id":"","url":"https://api.github.com/users/toobaz","html_url":"https://github.com/toobaz","followers_url":"https://api.github.com/users/toobaz/followers","following_url":"https://api.github.com/users/toobaz/following{/other_user}","gists_url":"https://api.github.com/users/toobaz/gists{/gist_id}","starred_url":"https://api.github.com/users/toobaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toobaz/subscriptions","organizations_url":"https://api.github.com/users/toobaz/orgs","repos_url":"https://api.github.com/users/toobaz/repos","events_url":"https://api.github.com/users/toobaz/events{/privacy}","received_events_url":"https://api.github.com/users/toobaz/received_events","type":"User","site_admin":false},"labels":[{"id":195648009,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/Effort%20Low","name":"Effort Low","color":"006b75","default":false},{"id":71268330,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/MultiIndex","name":"MultiIndex","color":"207de5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-21T11:02:42Z","updated_at":"2018-05-23T02:22:11Z","closed_at":null,"author_association":"MEMBER","body":"#### Code Sample, a copy-pastable example if possible\r\n\r\n```python\r\nIn [2]: mi = pd.MultiIndex.from_product([[0, 1]])\r\n\r\nIn [3]: mi.set_names(('first',), level=0)\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-3-1f4ad6c7f0bf> in <module>()\r\n----> 1 mi.set_names(('first',), level=0)\r\n\r\n/home/nobackup/repo/pandas/pandas/core/indexes/base.py in set_names(self, names, level, inplace)\r\n   1386 \r\n   1387         if level is not None and self.nlevels == 1:\r\n-> 1388             raise ValueError('Level must be None for non-MultiIndex')\r\n   1389 \r\n   1390         if level is not None and not is_list_like(level) and is_list_like(\r\n\r\nValueError: Level must be None for non-MultiIndex\r\n\r\n```\r\n\r\n#### Problem description\r\n\r\nThe case of ``MultiIndex`` with ``self.nlevels == 1`` is currently perfectly valid (despite e.g. ``MultiIndex.droplevel`` returning a normal ``Index`` when only one level is left). Unless we want to change this, we should always identify a ``MultiIndex`` with ``isinstance``, not by looking at ``self.nlevels``.\r\n\r\n#### Expected Output\r\n\r\n```python\r\nIn [4]: mi.set_names(('first',))\r\nOut[4]: \r\nMultiIndex(levels=[[0, 1]],\r\n           labels=[[0, 1]],\r\n           names=['first'])\r\n```\r\n\r\n#### Output of ``pd.show_versions()``\r\n\r\n<details>\r\n\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: 5cf4957a2cc8429170742dd1e6435ddb8c323811\r\npython: 3.5.3.final.0\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 4.9.0-6-amd64\r\nmachine: x86_64\r\nprocessor: \r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: it_IT.UTF-8\r\nLOCALE: it_IT.UTF-8\r\n\r\npandas: 0.24.0.dev0+14.g5cf4957a2.dirty\r\npytest: 3.5.0\r\npip: 9.0.1\r\nsetuptools: 39.0.1\r\nCython: 0.25.2\r\nnumpy: 1.14.3\r\nscipy: 0.19.0\r\npyarrow: None\r\nxarray: None\r\nIPython: 6.2.1\r\nsphinx: 1.5.6\r\npatsy: 0.5.0\r\ndateutil: 2.7.3\r\npytz: 2018.4\r\nblosc: None\r\nbottleneck: 1.2.0dev\r\ntables: 3.3.0\r\nnumexpr: 2.6.1\r\nfeather: 0.3.1\r\nmatplotlib: 2.0.0\r\nopenpyxl: 2.3.0\r\nxlrd: 1.0.0\r\nxlwt: 1.3.0\r\nxlsxwriter: 0.9.6\r\nlxml: 4.1.1\r\nbs4: 4.5.3\r\nhtml5lib: 0.999999999\r\nsqlalchemy: 1.0.15\r\npymysql: None\r\npsycopg2: None\r\njinja2: 2.10\r\ns3fs: None\r\nfastparquet: None\r\npandas_gbq: None\r\npandas_datareader: 0.2.1\r\n\r\n\r\n</details>\r\n"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/391199466","html_url":"https://github.com/pandas-dev/pandas/issues/21149#issuecomment-391199466","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21149","id":391199466,"user":{"login":"KalyanGokhale","id":4734245,"avatar_url":"https://avatars0.githubusercontent.com/u/4734245?v=4","gravatar_id":"","url":"https://api.github.com/users/KalyanGokhale","html_url":"https://github.com/KalyanGokhale","followers_url":"https://api.github.com/users/KalyanGokhale/followers","following_url":"https://api.github.com/users/KalyanGokhale/following{/other_user}","gists_url":"https://api.github.com/users/KalyanGokhale/gists{/gist_id}","starred_url":"https://api.github.com/users/KalyanGokhale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KalyanGokhale/subscriptions","organizations_url":"https://api.github.com/users/KalyanGokhale/orgs","repos_url":"https://api.github.com/users/KalyanGokhale/repos","events_url":"https://api.github.com/users/KalyanGokhale/events{/privacy}","received_events_url":"https://api.github.com/users/KalyanGokhale/received_events","type":"User","site_admin":false},"created_at":"2018-05-23T02:22:11Z","updated_at":"2018-05-23T02:22:11Z","author_association":"CONTRIBUTOR","body":"Sure - of two `self.nlevels` statement in `def set_names`, at one place change is needed and at the other its not needed - and I have made the fix.\r\n\r\nFor one `self.nlevels` statement in `def cmp_method` in the same file `pandas/core/indexes/base.py`, I am evaluating a few test cases - and will submit a single PR once done."}}
{"actor":{"display_login":"KalyanGokhale"}}