{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/21726","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21726/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21726/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21726/events","html_url":"https://github.com/pandas-dev/pandas/issues/21726","id":338214518,"node_id":"MDU6SXNzdWUzMzgyMTQ1MTg=","number":21726,"title":"DataFrame.replace doesn't work with categorical data","user":{"login":"lovasoa","id":552629,"node_id":"MDQ6VXNlcjU1MjYyOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/552629?v=4","gravatar_id":"","url":"https://api.github.com/users/lovasoa","html_url":"https://github.com/lovasoa","followers_url":"https://api.github.com/users/lovasoa/followers","following_url":"https://api.github.com/users/lovasoa/following{/other_user}","gists_url":"https://api.github.com/users/lovasoa/gists{/gist_id}","starred_url":"https://api.github.com/users/lovasoa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lovasoa/subscriptions","organizations_url":"https://api.github.com/users/lovasoa/orgs","repos_url":"https://api.github.com/users/lovasoa/repos","events_url":"https://api.github.com/users/lovasoa/events{/privacy}","received_events_url":"https://api.github.com/users/lovasoa/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-04T10:10:41Z","updated_at":"2018-07-04T10:58:32Z","closed_at":"2018-07-04T10:58:32Z","author_association":"NONE","body":"#### Code Sample\r\n\r\n```python\r\nimport pandas as pd\r\ndf = pd.DataFrame([\"x\", \"y\", \"z\"], dtype='category')\r\ndf.replace({\"x\": \"y\"})\r\n```\r\n\r\n#### Problem description\r\n\r\n##### Current output \r\n```\r\n~/.local/lib/python3.6/site-packages/pandas/core/internals.py in __init__(self, values, placement, ndim, fastpath)\r\n    109             ndim = values.ndim\r\n    110         elif values.ndim != ndim:\r\n--> 111             raise ValueError('Wrong number of dimensions')\r\n    112         self.ndim = ndim\r\n    113 \r\n\r\nValueError: Wrong number of dimensions\r\n```\r\n##### Expected output \r\nThe following DataFrame:\r\n\r\n```\r\n   0\r\n0  y\r\n1  y\r\n2  z\r\n```\r\n\r\n##### Explanation\r\nAt the very least, the error message is confusing. But I think this is a bug in the `replace` method, that should just work with categorical data.\r\n\r\nThis problem has confused other people before: https://stackoverflow.com/questions/48807344/how-to-replace-values-in-multiple-categoricals-in-a-pandas-dataframe\r\n\r\n\r\n#### Output of ``pd.show_versions()``\r\n\r\n<details>\r\n\r\ncommit: None\r\npython: 3.6.5.final.0\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 4.17.3-200.fc28.x86_64\r\nmachine: x86_64\r\nprocessor: x86_64\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_GB.UTF-8\r\nLOCALE: en_GB.UTF-8\r\n\r\npandas: 0.22.0\r\npytest: 3.3.2\r\npip: 9.0.3\r\nsetuptools: 39.2.0\r\nCython: 0.27.3\r\nnumpy: 1.14.1\r\nscipy: 0.19.1\r\npyarrow: None\r\nxarray: None\r\nIPython: 6.4.0\r\nsphinx: None\r\npatsy: None\r\ndateutil: 2.6.1\r\npytz: 2018.3\r\nblosc: None\r\nbottleneck: None\r\ntables: None\r\nnumexpr: None\r\nfeather: None\r\nmatplotlib: 2.0.2\r\nopenpyxl: None\r\nxlrd: None\r\nxlwt: None\r\nxlsxwriter: None\r\nlxml: None\r\nbs4: None\r\nhtml5lib: 0.9999999\r\nsqlalchemy: 1.2.7\r\npymysql: None\r\npsycopg2: None\r\njinja2: 2.10\r\ns3fs: None\r\nfastparquet: None\r\npandas_gbq: None\r\npandas_datareader: None\r\n\r\n</details>\r\n"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/402444678","html_url":"https://github.com/pandas-dev/pandas/issues/21726#issuecomment-402444678","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/21726","id":402444678,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjQ0NDY3OA==","user":{"login":"TomAugspurger","id":1312546,"node_id":"MDQ6VXNlcjEzMTI1NDY=","avatar_url":"https://avatars3.githubusercontent.com/u/1312546?v=4","gravatar_id":"","url":"https://api.github.com/users/TomAugspurger","html_url":"https://github.com/TomAugspurger","followers_url":"https://api.github.com/users/TomAugspurger/followers","following_url":"https://api.github.com/users/TomAugspurger/following{/other_user}","gists_url":"https://api.github.com/users/TomAugspurger/gists{/gist_id}","starred_url":"https://api.github.com/users/TomAugspurger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomAugspurger/subscriptions","organizations_url":"https://api.github.com/users/TomAugspurger/orgs","repos_url":"https://api.github.com/users/TomAugspurger/repos","events_url":"https://api.github.com/users/TomAugspurger/events{/privacy}","received_events_url":"https://api.github.com/users/TomAugspurger/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T10:58:32Z","updated_at":"2018-07-04T10:58:32Z","author_association":"CONTRIBUTOR","body":"Duplicate of https://github.com/pandas-dev/pandas/issues/18250\r\n\r\nAs of 0.23 or master (not sure which) the categorical is coerced to objects and the replacement happens. Ideally it wouldn't coerce to object."}}
{"actor":{"display_login":"TomAugspurger"}}