{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/9836","labels_url":"https://api.github.com/repos/pydata/pandas/issues/9836/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/9836/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/9836/events","html_url":"https://github.com/pydata/pandas/issues/9836","id":67145505,"number":9836,"title":"less than, greater than cuts on categorical don't follow order","user":{"login":"olgabot","id":806256,"avatar_url":"https://avatars.githubusercontent.com/u/806256?v=3","gravatar_id":"","url":"https://api.github.com/users/olgabot","html_url":"https://github.com/olgabot","followers_url":"https://api.github.com/users/olgabot/followers","following_url":"https://api.github.com/users/olgabot/following{/other_user}","gists_url":"https://api.github.com/users/olgabot/gists{/gist_id}","starred_url":"https://api.github.com/users/olgabot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgabot/subscriptions","organizations_url":"https://api.github.com/users/olgabot/orgs","repos_url":"https://api.github.com/users/olgabot/repos","events_url":"https://api.github.com/users/olgabot/events{/privacy}","received_events_url":"https://api.github.com/users/olgabot/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pydata/pandas/labels/API%20Design","name":"API Design","color":"AD7FA8"},{"url":"https://api.github.com/repos/pydata/pandas/labels/Categorical","name":"Categorical","color":"e11d21"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/pydata/pandas/milestones/29","html_url":"https://github.com/pydata/pandas/milestones/0.16.1","labels_url":"https://api.github.com/repos/pydata/pandas/milestones/29/labels","id":816810,"number":29,"title":"0.16.1","description":"after 0.16.0 of course!","creator":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"open_issues":106,"closed_issues":111,"state":"open","created_at":"2014-10-07T14:39:07Z","updated_at":"2015-04-15T21:03:00Z","due_on":"2015-04-30T07:00:00Z","closed_at":null},"comments":47,"created_at":"2015-04-08T14:40:25Z","updated_at":"2015-04-15T22:01:56Z","closed_at":"2015-04-11T20:07:12Z","body":"When subsetting an ordered `pd.Categorical` object using less than/greater than on the ordered values, the less/than greater than follow lexicographical order, not categorical order.\r\n\r\nIf you create a dataframe and assign categories, you can subset:\r\n\r\n```\r\nIn [1]: import pandas as pd\r\n\r\nIn [2]: import numpy as np\r\n\r\nIn [3]: df = pd.DataFrame({'x':np.arange(10), 'y':list('AAAABBBCCC')})\r\n\r\nIn [4]: df.y = df.y.astype('category')\r\n\r\nIn [5]: df.ix[(df.y >= \"A\") & (df.y <= \"B\")]\r\nOut[5]: \r\n   x  y\r\n0  0  A\r\n1  1  A\r\n2  2  A\r\n3  3  A\r\n4  4  B\r\n5  5  B\r\n6  6  B\r\n```\r\n\r\nBut if you try to subset on an ordered category, it does the lexicographical order instead:\r\n\r\n```\r\nIn [6]: df = pd.DataFrame({'x':np.arange(10), 'y':list('AAAABBBCCC')})\r\n\r\nIn [7]: df.y = pd.Categorical(df.y, categories=['A', 'C', 'B'], ordered=True)\r\n\r\nIn [8]: df.ix[(df.y >= \"A\") & (df.y <= \"C\")]\r\nOut[8]: \r\n   x  y\r\n0  0  A\r\n1  1  A\r\n2  2  A\r\n3  3  A\r\n4  4  B\r\n5  5  B\r\n6  6  B\r\n7  7  C\r\n8  8  C\r\n9  9  C\r\n```"},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/93581332","html_url":"https://github.com/pydata/pandas/issues/9836#issuecomment-93581332","issue_url":"https://api.github.com/repos/pydata/pandas/issues/9836","id":93581332,"user":{"login":"kay1793","id":9023555,"avatar_url":"https://avatars.githubusercontent.com/u/9023555?v=3","gravatar_id":"","url":"https://api.github.com/users/kay1793","html_url":"https://github.com/kay1793","followers_url":"https://api.github.com/users/kay1793/followers","following_url":"https://api.github.com/users/kay1793/following{/other_user}","gists_url":"https://api.github.com/users/kay1793/gists{/gist_id}","starred_url":"https://api.github.com/users/kay1793/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kay1793/subscriptions","organizations_url":"https://api.github.com/users/kay1793/orgs","repos_url":"https://api.github.com/users/kay1793/repos","events_url":"https://api.github.com/users/kay1793/events{/privacy}","received_events_url":"https://api.github.com/users/kay1793/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T22:01:55Z","updated_at":"2015-04-15T22:01:55Z","body":"once people begin to create packages solely to avoid what is considered \"idiomatic\" code... might be a good idea to take notice."}}