{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/22710","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22710/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22710/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22710/events","html_url":"https://github.com/pandas-dev/pandas/pull/22710","id":360317947,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE1NjA0NjQ1","number":22710,"title":"BUG: Empty CategoricalIndex fails with boolean categories","user":{"login":"pganssle","id":1377457,"node_id":"MDQ6VXNlcjEzNzc0NTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1377457?v=4","gravatar_id":"","url":"https://api.github.com/users/pganssle","html_url":"https://github.com/pganssle","followers_url":"https://api.github.com/users/pganssle/followers","following_url":"https://api.github.com/users/pganssle/following{/other_user}","gists_url":"https://api.github.com/users/pganssle/gists{/gist_id}","starred_url":"https://api.github.com/users/pganssle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pganssle/subscriptions","organizations_url":"https://api.github.com/users/pganssle/orgs","repos_url":"https://api.github.com/users/pganssle/repos","events_url":"https://api.github.com/users/pganssle/events{/privacy}","received_events_url":"https://api.github.com/users/pganssle/received_events","type":"User","site_admin":false},"labels":[{"id":76811,"node_id":"MDU6TGFiZWw3NjgxMQ==","url":"https://api.github.com/repos/pandas-dev/pandas/labels/Bug","name":"Bug","color":"e10c02","default":false},{"id":78527356,"node_id":"MDU6TGFiZWw3ODUyNzM1Ng==","url":"https://api.github.com/repos/pandas-dev/pandas/labels/Categorical","name":"Categorical","color":"e11d21","default":false},{"id":31404521,"node_id":"MDU6TGFiZWwzMTQwNDUyMQ==","url":"https://api.github.com/repos/pandas-dev/pandas/labels/Dtypes","name":"Dtypes","color":"e102d8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/pandas-dev/pandas/milestones/55","html_url":"https://github.com/pandas-dev/pandas/milestone/55","labels_url":"https://api.github.com/repos/pandas-dev/pandas/milestones/55/labels","id":3228419,"node_id":"MDk6TWlsZXN0b25lMzIyODQxOQ==","number":55,"title":"0.24.0","description":"","creator":{"login":"jorisvandenbossche","id":1020496,"node_id":"MDQ6VXNlcjEwMjA0OTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1020496?v=4","gravatar_id":"","url":"https://api.github.com/users/jorisvandenbossche","html_url":"https://github.com/jorisvandenbossche","followers_url":"https://api.github.com/users/jorisvandenbossche/followers","following_url":"https://api.github.com/users/jorisvandenbossche/following{/other_user}","gists_url":"https://api.github.com/users/jorisvandenbossche/gists{/gist_id}","starred_url":"https://api.github.com/users/jorisvandenbossche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorisvandenbossche/subscriptions","organizations_url":"https://api.github.com/users/jorisvandenbossche/orgs","repos_url":"https://api.github.com/users/jorisvandenbossche/repos","events_url":"https://api.github.com/users/jorisvandenbossche/events{/privacy}","received_events_url":"https://api.github.com/users/jorisvandenbossche/received_events","type":"User","site_admin":false},"open_issues":147,"closed_issues":677,"state":"open","created_at":"2018-03-29T12:00:12Z","updated_at":"2018-09-20T12:54:21Z","due_on":"2018-09-30T07:00:00Z","closed_at":null},"comments":7,"created_at":"2018-09-14T14:02:41Z","updated_at":"2018-09-20T13:33:32Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/pandas-dev/pandas/pulls/22710","html_url":"https://github.com/pandas-dev/pandas/pull/22710","diff_url":"https://github.com/pandas-dev/pandas/pull/22710.diff","patch_url":"https://github.com/pandas-dev/pandas/pull/22710.patch"},"body":"Fixes #22702.\r\n\r\nThis bug was introduced in [7818486859d1aba53](https://github.com/pandas-dev/pandas/commit/7818486859d1aba53ce359b93cfc772e688958e5); per [my comment](https://github.com/pandas-dev/pandas/issues/22702#issuecomment-421364087), the problem is here:\r\n\r\n```python\r\n    if not is_dtype_equal(values.dtype, categories.dtype):\r\n        values = ensure_object(values)\r\n        categories = ensure_object(categories)\r\n\r\n    (hash_klass, vec_klass), vals = _get_data_algo(values, _hashtables)\r\n    (_, _), cats = _get_data_algo(categories, _hashtables)\r\n```\r\n\r\nWhen `categories` is `Index([True], dtype='object')` and `values` is `array([], dtype='object')`, the `ensure_object` call is bypassed, but in `_get_data_algo`, an `Index` consisting entirely of boolean objects will be coerced to `uint64`, which violates the assumption that `values` and `categories` have the same dtype.\r\n\r\nI felt that retrieving the underlying numpy arrays (if any exist) is the safest way to handle this without having too many wide-reaching effects across the rest of the codebase, but there might be a better way to enforce that these are not coerced into different data types.\r\n\r\n- [x] closes #xxxx\r\n- [x] tests added \r\n- [x] passes `git diff upstream/master -u -- \"*.py\" | flake8 --diff`\r\n- [x] whatsnew entry\r\n"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/423184665","html_url":"https://github.com/pandas-dev/pandas/pull/22710#issuecomment-423184665","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/22710","id":423184665,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzE4NDY2NQ==","user":{"login":"pganssle","id":1377457,"node_id":"MDQ6VXNlcjEzNzc0NTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1377457?v=4","gravatar_id":"","url":"https://api.github.com/users/pganssle","html_url":"https://github.com/pganssle","followers_url":"https://api.github.com/users/pganssle/followers","following_url":"https://api.github.com/users/pganssle/following{/other_user}","gists_url":"https://api.github.com/users/pganssle/gists{/gist_id}","starred_url":"https://api.github.com/users/pganssle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pganssle/subscriptions","organizations_url":"https://api.github.com/users/pganssle/orgs","repos_url":"https://api.github.com/users/pganssle/repos","events_url":"https://api.github.com/users/pganssle/events{/privacy}","received_events_url":"https://api.github.com/users/pganssle/received_events","type":"User","site_admin":false},"created_at":"2018-09-20T13:33:32Z","updated_at":"2018-09-20T13:33:32Z","author_association":"CONTRIBUTOR","body":"@TomAugspurger Green now."}}
{"actor":{"display_login":"pganssle"}}