{"action":"opened","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/22527","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22527/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22527/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22527/events","html_url":"https://github.com/pandas-dev/pandas/issues/22527","id":354641203,"node_id":"MDU6SXNzdWUzNTQ2NDEyMDM=","number":22527,"title":"Series.map on a categorical does not process missing values","user":{"login":"batterseapower","id":18488,"node_id":"MDQ6VXNlcjE4NDg4","avatar_url":"https://avatars3.githubusercontent.com/u/18488?v=4","gravatar_id":"","url":"https://api.github.com/users/batterseapower","html_url":"https://github.com/batterseapower","followers_url":"https://api.github.com/users/batterseapower/followers","following_url":"https://api.github.com/users/batterseapower/following{/other_user}","gists_url":"https://api.github.com/users/batterseapower/gists{/gist_id}","starred_url":"https://api.github.com/users/batterseapower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/batterseapower/subscriptions","organizations_url":"https://api.github.com/users/batterseapower/orgs","repos_url":"https://api.github.com/users/batterseapower/repos","events_url":"https://api.github.com/users/batterseapower/events{/privacy}","received_events_url":"https://api.github.com/users/batterseapower/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-28T09:16:31Z","updated_at":"2018-08-28T09:16:31Z","closed_at":null,"author_association":"NONE","body":"#### Code Sample\r\n\r\n```python\r\n>>> pd.Series(['Pandas', 'is', np.nan], dtype='category').map(lambda x: len(x) if x == x else -1)\r\n0    6.0\r\n1    2.0\r\n2    NaN\r\ndtype: category\r\nCategories (2, int64): [6, 2]\r\n>>> pd.Series(['Pandas', 'is', np.nan], dtype='category').astype(object).map(lambda x: len(x) if x == x else -1)\r\n0    6\r\n1    2\r\n2   -1\r\ndtype: int64\r\n```\r\n#### Problem description\r\n\r\nSeries.map calls its function argument once for each value in the categorical, but never calls it on NaN even if that is part of the series. This is inconsistent with how Series.map usually works, and is very surprising!\r\n\r\nI'm raising this issue even though #15706 already exists because that issue is asking for something different (they want the argument to .map to be called once per value in the series, rather than once per unique value).\r\n\r\nAnother related issue is #20714.\r\n\r\n#### Expected Output\r\n\r\nCategorical map should give values equal to those obtained by first converting to object. For any series `s` and function `f` we should have the invariant that:\r\n\r\n```\r\ns.map(f).astype(object).equals(s.astype(object).map(f).astype(object))\r\n```\r\n\r\n#### Output of ``pd.show_versions()``\r\n\r\n<details>\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.6.1.final.0\r\npython-bits: 64\r\nOS: Windows\r\nOS-release: 10\r\nmachine: AMD64\r\nprocessor: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: None\r\nLOCALE: None.None\r\n\r\npandas: 0.23.1\r\npytest: 3.1.2\r\npip: 18.0\r\nsetuptools: 39.0.1\r\nCython: 0.27.2\r\nnumpy: 1.14.3\r\nscipy: 1.1.0\r\npyarrow: 0.9.0\r\nxarray: None\r\nIPython: 6.1.0\r\nsphinx: None\r\npatsy: 0.4.1\r\ndateutil: 2.7.2\r\npytz: 2018.3\r\nblosc: None\r\nbottleneck: 1.2.1\r\ntables: None\r\nnumexpr: None\r\nfeather: None\r\nmatplotlib: 2.2.2\r\nopenpyxl: None\r\nxlrd: None\r\nxlwt: None\r\nxlsxwriter: None\r\nlxml: 3.8.0\r\nbs4: 4.6.0\r\nhtml5lib: 0.9999999\r\nsqlalchemy: 1.1.11\r\npymysql: None\r\npsycopg2: None\r\njinja2: 2.9.6\r\ns3fs: None\r\nfastparquet: 0.1.5\r\npandas_gbq: None\r\npandas_datareader: None\r\n</details>\r\n"}}
{"actor":{"display_login":"batterseapower"}}