{"action":"created","comment":{"url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/comments/180766738","pull_request_review_id":111244917,"id":180766738,"diff_hunk":"@@ -319,9 +341,23 @@ def _get_index_loc(self, key, base_index=None):\n                                             periods=len(index) + 1,\n                                             freq=base_index.freq)\n \n-        # Get the location (note that get_loc will throw a KeyError if key is\n-        # invalid)\n-        loc = index.get_loc(key)\n+        # Get the location\n+        if date_index:\n+            # (note that get_loc will throw a KeyError if key is invalid)\n+            loc = index.get_loc(key)\n+        elif int_index or range_index:\n+            # For Int64Index and RangeIndex, key is assumed to be the location\n+            # and not an index value (this assumption is required to support\n+            # RangeIndex)\n+            try:\n+                index[key]\n+            # We want to raise a KeyError in this case, to keep the exception\n+            # consistent across index types\n+            except IndexError as e:","path":"statsmodels/tsa/base/tsa_model.py","position":91,"original_position":91,"commit_id":"f9f8c92874e97c36dd0cf143715845ec5509e317","original_commit_id":"f9f8c92874e97c36dd0cf143715845ec5509e317","user":{"login":"ChadFulton","id":280864,"avatar_url":"https://avatars0.githubusercontent.com/u/280864?v=4","gravatar_id":"","url":"https://api.github.com/users/ChadFulton","html_url":"https://github.com/ChadFulton","followers_url":"https://api.github.com/users/ChadFulton/followers","following_url":"https://api.github.com/users/ChadFulton/following{/other_user}","gists_url":"https://api.github.com/users/ChadFulton/gists{/gist_id}","starred_url":"https://api.github.com/users/ChadFulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChadFulton/subscriptions","organizations_url":"https://api.github.com/users/ChadFulton/orgs","repos_url":"https://api.github.com/users/ChadFulton/repos","events_url":"https://api.github.com/users/ChadFulton/events{/privacy}","received_events_url":"https://api.github.com/users/ChadFulton/received_events","type":"User","site_admin":false},"body":"First, to be honest, I do not fully understand the design decisions between `KeyError` and `IndexError` in Pandas. For example, the following:\r\n\r\n```python\r\nx = pd.Int64Index(np.arange(10))\r\nx.get_loc(11)  # raises KeyError\r\nx[11]          # raises IndexError\r\n```\r\n\r\nNow, this part of the code is relying on Pandas to tell me if the key is invalid (i.e. we don't want to have to figure it out ourselves), and we'd ideally like to check using `index.get_loc(key)` so that it works with date strings, etc. This also works fine for incrementing `Int64Index`es, but the problem is that for `RangeIndex`, the index values are integers too, so for example:\r\n\r\n```python\r\nx = pd.RangeIndex(start=0, stop=10, step=2)\r\nprint(x.get_loc(2))  # 1\r\nprint(x[2])          # 4\r\n```\r\n\r\nNow in this code I want to check that the key is a valid part of the index, so for a `RangeIndex` I have to do that using `index[key]` rather than `index.get_loc(key)` and for some reason this raises an `IndexError`. Intuitively, though, I'm searching for the existence of a key, and I want to raise a `KeyError` if it doesn't exist.\r\n\r\nIf there's a better way to do this check consistently, that's good too.","created_at":"2018-04-11T14:07:53Z","updated_at":"2018-04-11T14:07:53Z","html_url":"https://github.com/statsmodels/statsmodels/pull/4457#discussion_r180766738","pull_request_url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/comments/180766738"},"html":{"href":"https://github.com/statsmodels/statsmodels/pull/4457#discussion_r180766738"},"pull_request":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457"}},"in_reply_to_id":180291418},"pull_request":{"url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457","id":180462301,"html_url":"https://github.com/statsmodels/statsmodels/pull/4457","diff_url":"https://github.com/statsmodels/statsmodels/pull/4457.diff","patch_url":"https://github.com/statsmodels/statsmodels/pull/4457.patch","issue_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/4457","number":4457,"state":"open","locked":false,"title":"ENH: Add support for RangeIndexes","user":{"login":"ChadFulton","id":280864,"avatar_url":"https://avatars0.githubusercontent.com/u/280864?v=4","gravatar_id":"","url":"https://api.github.com/users/ChadFulton","html_url":"https://github.com/ChadFulton","followers_url":"https://api.github.com/users/ChadFulton/followers","following_url":"https://api.github.com/users/ChadFulton/following{/other_user}","gists_url":"https://api.github.com/users/ChadFulton/gists{/gist_id}","starred_url":"https://api.github.com/users/ChadFulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChadFulton/subscriptions","organizations_url":"https://api.github.com/users/ChadFulton/orgs","repos_url":"https://api.github.com/users/ChadFulton/repos","events_url":"https://api.github.com/users/ChadFulton/events{/privacy}","received_events_url":"https://api.github.com/users/ChadFulton/received_events","type":"User","site_admin":false},"body":"As of Pandas 0.18, the default index is `RangeIndex` rather than `Int64Index`. We only directly supported `Int64Index` (along with date indexes) so a warning would be issued by tsa models that the index would be ignored.\r\n\r\nThis adds direct support for `RangeIndex`es of all types.","created_at":"2018-04-10T00:39:05Z","updated_at":"2018-04-11T14:07:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"297e0ad8c1ecd8d401d5b5a941ae59fdc443f452","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":142959,"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-tsa","name":"comp-tsa","color":"ededed","default":false},{"id":142961,"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/type-enh","name":"type-enh","color":"99ffff","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457/commits","review_comments_url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457/comments","review_comment_url":"https://api.github.com/repos/statsmodels/statsmodels/pulls/comments{/number}","comments_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/4457/comments","statuses_url":"https://api.github.com/repos/statsmodels/statsmodels/statuses/f9f8c92874e97c36dd0cf143715845ec5509e317","head":{"label":"ChadFulton:pd-rangeindex","ref":"pd-rangeindex","sha":"f9f8c92874e97c36dd0cf143715845ec5509e317","user":{"login":"ChadFulton","id":280864,"avatar_url":"https://avatars0.githubusercontent.com/u/280864?v=4","gravatar_id":"","url":"https://api.github.com/users/ChadFulton","html_url":"https://github.com/ChadFulton","followers_url":"https://api.github.com/users/ChadFulton/followers","following_url":"https://api.github.com/users/ChadFulton/following{/other_user}","gists_url":"https://api.github.com/users/ChadFulton/gists{/gist_id}","starred_url":"https://api.github.com/users/ChadFulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChadFulton/subscriptions","organizations_url":"https://api.github.com/users/ChadFulton/orgs","repos_url":"https://api.github.com/users/ChadFulton/repos","events_url":"https://api.github.com/users/ChadFulton/events{/privacy}","received_events_url":"https://api.github.com/users/ChadFulton/received_events","type":"User","site_admin":false},"repo":{"id":9765991,"name":"statsmodels","full_name":"ChadFulton/statsmodels","owner":{"login":"ChadFulton","id":280864,"avatar_url":"https://avatars0.githubusercontent.com/u/280864?v=4","gravatar_id":"","url":"https://api.github.com/users/ChadFulton","html_url":"https://github.com/ChadFulton","followers_url":"https://api.github.com/users/ChadFulton/followers","following_url":"https://api.github.com/users/ChadFulton/following{/other_user}","gists_url":"https://api.github.com/users/ChadFulton/gists{/gist_id}","starred_url":"https://api.github.com/users/ChadFulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChadFulton/subscriptions","organizations_url":"https://api.github.com/users/ChadFulton/orgs","repos_url":"https://api.github.com/users/ChadFulton/repos","events_url":"https://api.github.com/users/ChadFulton/events{/privacy}","received_events_url":"https://api.github.com/users/ChadFulton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ChadFulton/statsmodels","description":"Statsmodels: statistical modeling and econometrics in Python","fork":true,"url":"https://api.github.com/repos/ChadFulton/statsmodels","forks_url":"https://api.github.com/repos/ChadFulton/statsmodels/forks","keys_url":"https://api.github.com/repos/ChadFulton/statsmodels/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ChadFulton/statsmodels/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ChadFulton/statsmodels/teams","hooks_url":"https://api.github.com/repos/ChadFulton/statsmodels/hooks","issue_events_url":"https://api.github.com/repos/ChadFulton/statsmodels/issues/events{/number}","events_url":"https://api.github.com/repos/ChadFulton/statsmodels/events","assignees_url":"https://api.github.com/repos/ChadFulton/statsmodels/assignees{/user}","branches_url":"https://api.github.com/repos/ChadFulton/statsmodels/branches{/branch}","tags_url":"https://api.github.com/repos/ChadFulton/statsmodels/tags","blobs_url":"https://api.github.com/repos/ChadFulton/statsmodels/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ChadFulton/statsmodels/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ChadFulton/statsmodels/git/refs{/sha}","trees_url":"https://api.github.com/repos/ChadFulton/statsmodels/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ChadFulton/statsmodels/statuses/{sha}","languages_url":"https://api.github.com/repos/ChadFulton/statsmodels/languages","stargazers_url":"https://api.github.com/repos/ChadFulton/statsmodels/stargazers","contributors_url":"https://api.github.com/repos/ChadFulton/statsmodels/contributors","subscribers_url":"https://api.github.com/repos/ChadFulton/statsmodels/subscribers","subscription_url":"https://api.github.com/repos/ChadFulton/statsmodels/subscription","commits_url":"https://api.github.com/repos/ChadFulton/statsmodels/commits{/sha}","git_commits_url":"https://api.github.com/repos/ChadFulton/statsmodels/git/commits{/sha}","comments_url":"https://api.github.com/repos/ChadFulton/statsmodels/comments{/number}","issue_comment_url":"https://api.github.com/repos/ChadFulton/statsmodels/issues/comments{/number}","contents_url":"https://api.github.com/repos/ChadFulton/statsmodels/contents/{+path}","compare_url":"https://api.github.com/repos/ChadFulton/statsmodels/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ChadFulton/statsmodels/merges","archive_url":"https://api.github.com/repos/ChadFulton/statsmodels/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ChadFulton/statsmodels/downloads","issues_url":"https://api.github.com/repos/ChadFulton/statsmodels/issues{/number}","pulls_url":"https://api.github.com/repos/ChadFulton/statsmodels/pulls{/number}","milestones_url":"https://api.github.com/repos/ChadFulton/statsmodels/milestones{/number}","notifications_url":"https://api.github.com/repos/ChadFulton/statsmodels/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ChadFulton/statsmodels/labels{/name}","releases_url":"https://api.github.com/repos/ChadFulton/statsmodels/releases{/id}","deployments_url":"https://api.github.com/repos/ChadFulton/statsmodels/deployments","created_at":"2013-04-30T07:16:46Z","updated_at":"2018-02-20T18:43:00Z","pushed_at":"2018-04-10T00:37:35Z","git_url":"git://github.com/ChadFulton/statsmodels.git","ssh_url":"git@github.com:ChadFulton/statsmodels.git","clone_url":"https://github.com/ChadFulton/statsmodels.git","svn_url":"https://github.com/ChadFulton/statsmodels","homepage":"http://statsmodels.sourceforge.net/devel/","size":27911,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":11,"open_issues":2,"watchers":7,"default_branch":"master"}},"base":{"label":"statsmodels:master","ref":"master","sha":"98d67db9e4854c073dc52cd6191315a88d075011","user":{"login":"statsmodels","id":717666,"avatar_url":"https://avatars3.githubusercontent.com/u/717666?v=4","gravatar_id":"","url":"https://api.github.com/users/statsmodels","html_url":"https://github.com/statsmodels","followers_url":"https://api.github.com/users/statsmodels/followers","following_url":"https://api.github.com/users/statsmodels/following{/other_user}","gists_url":"https://api.github.com/users/statsmodels/gists{/gist_id}","starred_url":"https://api.github.com/users/statsmodels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/statsmodels/subscriptions","organizations_url":"https://api.github.com/users/statsmodels/orgs","repos_url":"https://api.github.com/users/statsmodels/repos","events_url":"https://api.github.com/users/statsmodels/events{/privacy}","received_events_url":"https://api.github.com/users/statsmodels/received_events","type":"Organization","site_admin":false},"repo":{"id":1885237,"name":"statsmodels","full_name":"statsmodels/statsmodels","owner":{"login":"statsmodels","id":717666,"avatar_url":"https://avatars3.githubusercontent.com/u/717666?v=4","gravatar_id":"","url":"https://api.github.com/users/statsmodels","html_url":"https://github.com/statsmodels","followers_url":"https://api.github.com/users/statsmodels/followers","following_url":"https://api.github.com/users/statsmodels/following{/other_user}","gists_url":"https://api.github.com/users/statsmodels/gists{/gist_id}","starred_url":"https://api.github.com/users/statsmodels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/statsmodels/subscriptions","organizations_url":"https://api.github.com/users/statsmodels/orgs","repos_url":"https://api.github.com/users/statsmodels/repos","events_url":"https://api.github.com/users/statsmodels/events{/privacy}","received_events_url":"https://api.github.com/users/statsmodels/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/statsmodels/statsmodels","description":"Statsmodels: statistical modeling and econometrics in Python","fork":false,"url":"https://api.github.com/repos/statsmodels/statsmodels","forks_url":"https://api.github.com/repos/statsmodels/statsmodels/forks","keys_url":"https://api.github.com/repos/statsmodels/statsmodels/keys{/key_id}","collaborators_url":"https://api.github.com/repos/statsmodels/statsmodels/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/statsmodels/statsmodels/teams","hooks_url":"https://api.github.com/repos/statsmodels/statsmodels/hooks","issue_events_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/events{/number}","events_url":"https://api.github.com/repos/statsmodels/statsmodels/events","assignees_url":"https://api.github.com/repos/statsmodels/statsmodels/assignees{/user}","branches_url":"https://api.github.com/repos/statsmodels/statsmodels/branches{/branch}","tags_url":"https://api.github.com/repos/statsmodels/statsmodels/tags","blobs_url":"https://api.github.com/repos/statsmodels/statsmodels/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/statsmodels/statsmodels/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/statsmodels/statsmodels/git/refs{/sha}","trees_url":"https://api.github.com/repos/statsmodels/statsmodels/git/trees{/sha}","statuses_url":"https://api.github.com/repos/statsmodels/statsmodels/statuses/{sha}","languages_url":"https://api.github.com/repos/statsmodels/statsmodels/languages","stargazers_url":"https://api.github.com/repos/statsmodels/statsmodels/stargazers","contributors_url":"https://api.github.com/repos/statsmodels/statsmodels/contributors","subscribers_url":"https://api.github.com/repos/statsmodels/statsmodels/subscribers","subscription_url":"https://api.github.com/repos/statsmodels/statsmodels/subscription","commits_url":"https://api.github.com/repos/statsmodels/statsmodels/commits{/sha}","git_commits_url":"https://api.github.com/repos/statsmodels/statsmodels/git/commits{/sha}","comments_url":"https://api.github.com/repos/statsmodels/statsmodels/comments{/number}","issue_comment_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/comments{/number}","contents_url":"https://api.github.com/repos/statsmodels/statsmodels/contents/{+path}","compare_url":"https://api.github.com/repos/statsmodels/statsmodels/compare/{base}...{head}","merges_url":"https://api.github.com/repos/statsmodels/statsmodels/merges","archive_url":"https://api.github.com/repos/statsmodels/statsmodels/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/statsmodels/statsmodels/downloads","issues_url":"https://api.github.com/repos/statsmodels/statsmodels/issues{/number}","pulls_url":"https://api.github.com/repos/statsmodels/statsmodels/pulls{/number}","milestones_url":"https://api.github.com/repos/statsmodels/statsmodels/milestones{/number}","notifications_url":"https://api.github.com/repos/statsmodels/statsmodels/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/labels{/name}","releases_url":"https://api.github.com/repos/statsmodels/statsmodels/releases{/id}","deployments_url":"https://api.github.com/repos/statsmodels/statsmodels/deployments","created_at":"2011-06-12T17:04:50Z","updated_at":"2018-04-11T12:59:48Z","pushed_at":"2018-04-11T12:59:14Z","git_url":"git://github.com/statsmodels/statsmodels.git","ssh_url":"git@github.com:statsmodels/statsmodels.git","clone_url":"https://github.com/statsmodels/statsmodels.git","svn_url":"https://github.com/statsmodels/statsmodels","homepage":"http://www.statsmodels.org/devel/","size":27768,"stargazers_count":2759,"watchers_count":2759,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1213,"mirror_url":null,"archived":false,"open_issues_count":1798,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":1213,"open_issues":1798,"watchers":2759,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457"},"html":{"href":"https://github.com/statsmodels/statsmodels/pull/4457"},"issue":{"href":"https://api.github.com/repos/statsmodels/statsmodels/issues/4457"},"comments":{"href":"https://api.github.com/repos/statsmodels/statsmodels/issues/4457/comments"},"review_comments":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457/comments"},"review_comment":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/statsmodels/statsmodels/pulls/4457/commits"},"statuses":{"href":"https://api.github.com/repos/statsmodels/statsmodels/statuses/f9f8c92874e97c36dd0cf143715845ec5509e317"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"ChadFulton"}}