{"action":"created","comment":{"url":"https://api.github.com/repos/pydata/xarray/pulls/comments/184904051","pull_request_review_id":116185485,"id":184904051,"diff_hunk":"@@ -203,18 +238,50 @@ def _infer_time_units_from_diff(unique_timedeltas):\n     return 'seconds'\n \n \n+def infer_calendar_name(dates):\n+    \"\"\"Given an array of datetimes, infer the CF calendar name\"\"\"\n+    if np.asarray(dates).dtype == 'datetime64[ns]':\n+        return 'proleptic_gregorian'\n+    else:\n+        try:\n+            return np.asarray(dates)[0].calendar\n+        except IndexError:\n+            return np.asarray(dates).item().calendar","path":"xarray/coding/times.py","position":168,"original_position":168,"commit_id":"ca4d7ddb4001e6c0615aac069471a411a4c64418","original_commit_id":"ca4d7ddb4001e6c0615aac069471a411a4c64418","user":{"login":"shoyer","id":1217238,"avatar_url":"https://avatars2.githubusercontent.com/u/1217238?v=4","gravatar_id":"","url":"https://api.github.com/users/shoyer","html_url":"https://github.com/shoyer","followers_url":"https://api.github.com/users/shoyer/followers","following_url":"https://api.github.com/users/shoyer/following{/other_user}","gists_url":"https://api.github.com/users/shoyer/gists{/gist_id}","starred_url":"https://api.github.com/users/shoyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoyer/subscriptions","organizations_url":"https://api.github.com/users/shoyer/orgs","repos_url":"https://api.github.com/users/shoyer/repos","events_url":"https://api.github.com/users/shoyer/events{/privacy}","received_events_url":"https://api.github.com/users/shoyer/received_events","type":"User","site_admin":false},"body":"Use something like `np.asarray(dates).ravel()[0]` to avoid the need for try/except.","created_at":"2018-04-30T01:51:41Z","updated_at":"2018-04-30T01:53:29Z","html_url":"https://github.com/pydata/xarray/pull/1252#discussion_r184904051","pull_request_url":"https://api.github.com/repos/pydata/xarray/pulls/1252","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/pydata/xarray/pulls/comments/184904051"},"html":{"href":"https://github.com/pydata/xarray/pull/1252#discussion_r184904051"},"pull_request":{"href":"https://api.github.com/repos/pydata/xarray/pulls/1252"}}},"pull_request":{"url":"https://api.github.com/repos/pydata/xarray/pulls/1252","id":104726723,"html_url":"https://github.com/pydata/xarray/pull/1252","diff_url":"https://github.com/pydata/xarray/pull/1252.diff","patch_url":"https://github.com/pydata/xarray/pull/1252.patch","issue_url":"https://api.github.com/repos/pydata/xarray/issues/1252","number":1252,"state":"open","locked":false,"title":"CFTimeIndex","user":{"login":"spencerkclark","id":6628425,"avatar_url":"https://avatars0.githubusercontent.com/u/6628425?v=4","gravatar_id":"","url":"https://api.github.com/users/spencerkclark","html_url":"https://github.com/spencerkclark","followers_url":"https://api.github.com/users/spencerkclark/followers","following_url":"https://api.github.com/users/spencerkclark/following{/other_user}","gists_url":"https://api.github.com/users/spencerkclark/gists{/gist_id}","starred_url":"https://api.github.com/users/spencerkclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spencerkclark/subscriptions","organizations_url":"https://api.github.com/users/spencerkclark/orgs","repos_url":"https://api.github.com/users/spencerkclark/repos","events_url":"https://api.github.com/users/spencerkclark/events{/privacy}","received_events_url":"https://api.github.com/users/spencerkclark/received_events","type":"User","site_admin":false},"body":" - [x] closes #1084\r\n - [x] passes ``git diff upstream/master | flake8 --diff``\r\n- [x] tests added / passed\r\n- [x] whatsnew entry\r\n\r\nThis work in progress PR is a start on implementing a ```NetCDFTimeIndex```, a subclass of pandas.Index, which closely mimics pandas.DatetimeIndex, but uses ```netcdftime._netcdftime.datetime``` objects.  Currently implemented in the new index are:\r\n- Partial datetime-string indexing (using strictly [ISO8601-format strings](https://en.wikipedia.org/wiki/ISO_8601), using a date parser implemented by @shoyer in https://github.com/pydata/xarray/issues/1084#issuecomment-274372547)\r\n- Field-accessors for year, month, day, hour, minute, second, and microsecond, to enable ```groupby``` operations on attributes of date objects\r\n\r\nThis index is meant as a step towards improving the handling of non-standard calendars and dates outside the range ```Timestamp('1677-09-21 00:12:43.145225')``` to ```Timestamp('2262-04-11 23:47:16.854775807')```.\r\n\r\n--------------\r\n\r\nFor now I have pushed only the code and some tests for the new index; I want to make sure the index is solid and well-tested before we consider integrating it into any of xarray's existing logic or writing any documentation.  \r\n\r\nRegarding the index, there are a couple remaining outstanding issues (that at least I'm aware of):\r\n\r\n1. Currently one can create non-sensical datetimes using ```netcdftime._netcdftime.datetime``` objects.  This means one can attempt to index with an out-of-bounds string or datetime without raising an error.  Could this possibly be addressed upstream?  For example:\r\n```\r\nIn [1]: from netcdftime import DatetimeNoLeap\r\n\r\nIn [2]: DatetimeNoLeap(2000, 45, 45)\r\nOut[2]: netcdftime._netcdftime.DatetimeNoLeap(2000, 45, 45, 0, 0, 0, 0, -1, 1)\r\n```\r\n2. I am looking to enable this index to be used in pandas.Series and pandas.DataFrame objects as well;  this requires implementing a ```get_value``` method.  I have taken @shoyer's suggested simplified approach from https://github.com/pydata/xarray/issues/1084#issuecomment-275963433, and tweaked it to also allow for slice indexing, so I think this is most of the way there.  A remaining to-do for me, however, is to implement something to allow for integer-indexing outside of ```iloc```, e.g.  if you have a pandas.Series ```series```, indexing with the syntax ```series[1]``` or ```series[1:3]```.\r\n\r\nHopefully this is a decent start; in particular I'm not an expert in writing tests so please let me know if there are improvements I can make to the structure and / or style I've used so far.  I'm happy to make changes.  I appreciate your help.","created_at":"2017-02-06T02:10:47Z","updated_at":"2018-04-30T01:53:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"333b2ca8c91142a8bd5b62a5ab3912690c456089","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":156998660,"url":"https://api.github.com/repos/pydata/xarray/labels/CF%20conventions","name":"CF conventions","color":"fbca04","default":false},{"id":114009979,"url":"https://api.github.com/repos/pydata/xarray/labels/pandas-like","name":"pandas-like","color":"5319e7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pydata/xarray/pulls/1252/commits","review_comments_url":"https://api.github.com/repos/pydata/xarray/pulls/1252/comments","review_comment_url":"https://api.github.com/repos/pydata/xarray/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pydata/xarray/issues/1252/comments","statuses_url":"https://api.github.com/repos/pydata/xarray/statuses/ca4d7ddb4001e6c0615aac069471a411a4c64418","head":{"label":"spencerkclark:NetCDFTimeIndex","ref":"NetCDFTimeIndex","sha":"ca4d7ddb4001e6c0615aac069471a411a4c64418","user":{"login":"spencerkclark","id":6628425,"avatar_url":"https://avatars0.githubusercontent.com/u/6628425?v=4","gravatar_id":"","url":"https://api.github.com/users/spencerkclark","html_url":"https://github.com/spencerkclark","followers_url":"https://api.github.com/users/spencerkclark/followers","following_url":"https://api.github.com/users/spencerkclark/following{/other_user}","gists_url":"https://api.github.com/users/spencerkclark/gists{/gist_id}","starred_url":"https://api.github.com/users/spencerkclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spencerkclark/subscriptions","organizations_url":"https://api.github.com/users/spencerkclark/orgs","repos_url":"https://api.github.com/users/spencerkclark/repos","events_url":"https://api.github.com/users/spencerkclark/events{/privacy}","received_events_url":"https://api.github.com/users/spencerkclark/received_events","type":"User","site_admin":false},"repo":{"id":75723356,"name":"xarray","full_name":"spencerkclark/xarray","owner":{"login":"spencerkclark","id":6628425,"avatar_url":"https://avatars0.githubusercontent.com/u/6628425?v=4","gravatar_id":"","url":"https://api.github.com/users/spencerkclark","html_url":"https://github.com/spencerkclark","followers_url":"https://api.github.com/users/spencerkclark/followers","following_url":"https://api.github.com/users/spencerkclark/following{/other_user}","gists_url":"https://api.github.com/users/spencerkclark/gists{/gist_id}","starred_url":"https://api.github.com/users/spencerkclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spencerkclark/subscriptions","organizations_url":"https://api.github.com/users/spencerkclark/orgs","repos_url":"https://api.github.com/users/spencerkclark/repos","events_url":"https://api.github.com/users/spencerkclark/events{/privacy}","received_events_url":"https://api.github.com/users/spencerkclark/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/spencerkclark/xarray","description":"N-D labeled arrays and datasets in Python","fork":true,"url":"https://api.github.com/repos/spencerkclark/xarray","forks_url":"https://api.github.com/repos/spencerkclark/xarray/forks","keys_url":"https://api.github.com/repos/spencerkclark/xarray/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spencerkclark/xarray/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spencerkclark/xarray/teams","hooks_url":"https://api.github.com/repos/spencerkclark/xarray/hooks","issue_events_url":"https://api.github.com/repos/spencerkclark/xarray/issues/events{/number}","events_url":"https://api.github.com/repos/spencerkclark/xarray/events","assignees_url":"https://api.github.com/repos/spencerkclark/xarray/assignees{/user}","branches_url":"https://api.github.com/repos/spencerkclark/xarray/branches{/branch}","tags_url":"https://api.github.com/repos/spencerkclark/xarray/tags","blobs_url":"https://api.github.com/repos/spencerkclark/xarray/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spencerkclark/xarray/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spencerkclark/xarray/git/refs{/sha}","trees_url":"https://api.github.com/repos/spencerkclark/xarray/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spencerkclark/xarray/statuses/{sha}","languages_url":"https://api.github.com/repos/spencerkclark/xarray/languages","stargazers_url":"https://api.github.com/repos/spencerkclark/xarray/stargazers","contributors_url":"https://api.github.com/repos/spencerkclark/xarray/contributors","subscribers_url":"https://api.github.com/repos/spencerkclark/xarray/subscribers","subscription_url":"https://api.github.com/repos/spencerkclark/xarray/subscription","commits_url":"https://api.github.com/repos/spencerkclark/xarray/commits{/sha}","git_commits_url":"https://api.github.com/repos/spencerkclark/xarray/git/commits{/sha}","comments_url":"https://api.github.com/repos/spencerkclark/xarray/comments{/number}","issue_comment_url":"https://api.github.com/repos/spencerkclark/xarray/issues/comments{/number}","contents_url":"https://api.github.com/repos/spencerkclark/xarray/contents/{+path}","compare_url":"https://api.github.com/repos/spencerkclark/xarray/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spencerkclark/xarray/merges","archive_url":"https://api.github.com/repos/spencerkclark/xarray/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spencerkclark/xarray/downloads","issues_url":"https://api.github.com/repos/spencerkclark/xarray/issues{/number}","pulls_url":"https://api.github.com/repos/spencerkclark/xarray/pulls{/number}","milestones_url":"https://api.github.com/repos/spencerkclark/xarray/milestones{/number}","notifications_url":"https://api.github.com/repos/spencerkclark/xarray/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spencerkclark/xarray/labels{/name}","releases_url":"https://api.github.com/repos/spencerkclark/xarray/releases{/id}","deployments_url":"https://api.github.com/repos/spencerkclark/xarray/deployments","created_at":"2016-12-06T11:03:41Z","updated_at":"2016-12-06T11:03:43Z","pushed_at":"2018-04-28T20:30:47Z","git_url":"git://github.com/spencerkclark/xarray.git","ssh_url":"git@github.com:spencerkclark/xarray.git","clone_url":"https://github.com/spencerkclark/xarray.git","svn_url":"https://github.com/spencerkclark/xarray","homepage":"http://xarray.pydata.org","size":12143,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pydata:master","ref":"master","sha":"c42cbe787d530db48575d73fe7a3910b0a0e4fd8","user":{"login":"pydata","id":1284191,"avatar_url":"https://avatars0.githubusercontent.com/u/1284191?v=4","gravatar_id":"","url":"https://api.github.com/users/pydata","html_url":"https://github.com/pydata","followers_url":"https://api.github.com/users/pydata/followers","following_url":"https://api.github.com/users/pydata/following{/other_user}","gists_url":"https://api.github.com/users/pydata/gists{/gist_id}","starred_url":"https://api.github.com/users/pydata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pydata/subscriptions","organizations_url":"https://api.github.com/users/pydata/orgs","repos_url":"https://api.github.com/users/pydata/repos","events_url":"https://api.github.com/users/pydata/events{/privacy}","received_events_url":"https://api.github.com/users/pydata/received_events","type":"Organization","site_admin":false},"repo":{"id":13221727,"name":"xarray","full_name":"pydata/xarray","owner":{"login":"pydata","id":1284191,"avatar_url":"https://avatars0.githubusercontent.com/u/1284191?v=4","gravatar_id":"","url":"https://api.github.com/users/pydata","html_url":"https://github.com/pydata","followers_url":"https://api.github.com/users/pydata/followers","following_url":"https://api.github.com/users/pydata/following{/other_user}","gists_url":"https://api.github.com/users/pydata/gists{/gist_id}","starred_url":"https://api.github.com/users/pydata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pydata/subscriptions","organizations_url":"https://api.github.com/users/pydata/orgs","repos_url":"https://api.github.com/users/pydata/repos","events_url":"https://api.github.com/users/pydata/events{/privacy}","received_events_url":"https://api.github.com/users/pydata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pydata/xarray","description":"N-D labeled arrays and datasets in Python","fork":false,"url":"https://api.github.com/repos/pydata/xarray","forks_url":"https://api.github.com/repos/pydata/xarray/forks","keys_url":"https://api.github.com/repos/pydata/xarray/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pydata/xarray/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pydata/xarray/teams","hooks_url":"https://api.github.com/repos/pydata/xarray/hooks","issue_events_url":"https://api.github.com/repos/pydata/xarray/issues/events{/number}","events_url":"https://api.github.com/repos/pydata/xarray/events","assignees_url":"https://api.github.com/repos/pydata/xarray/assignees{/user}","branches_url":"https://api.github.com/repos/pydata/xarray/branches{/branch}","tags_url":"https://api.github.com/repos/pydata/xarray/tags","blobs_url":"https://api.github.com/repos/pydata/xarray/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pydata/xarray/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pydata/xarray/git/refs{/sha}","trees_url":"https://api.github.com/repos/pydata/xarray/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pydata/xarray/statuses/{sha}","languages_url":"https://api.github.com/repos/pydata/xarray/languages","stargazers_url":"https://api.github.com/repos/pydata/xarray/stargazers","contributors_url":"https://api.github.com/repos/pydata/xarray/contributors","subscribers_url":"https://api.github.com/repos/pydata/xarray/subscribers","subscription_url":"https://api.github.com/repos/pydata/xarray/subscription","commits_url":"https://api.github.com/repos/pydata/xarray/commits{/sha}","git_commits_url":"https://api.github.com/repos/pydata/xarray/git/commits{/sha}","comments_url":"https://api.github.com/repos/pydata/xarray/comments{/number}","issue_comment_url":"https://api.github.com/repos/pydata/xarray/issues/comments{/number}","contents_url":"https://api.github.com/repos/pydata/xarray/contents/{+path}","compare_url":"https://api.github.com/repos/pydata/xarray/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pydata/xarray/merges","archive_url":"https://api.github.com/repos/pydata/xarray/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pydata/xarray/downloads","issues_url":"https://api.github.com/repos/pydata/xarray/issues{/number}","pulls_url":"https://api.github.com/repos/pydata/xarray/pulls{/number}","milestones_url":"https://api.github.com/repos/pydata/xarray/milestones{/number}","notifications_url":"https://api.github.com/repos/pydata/xarray/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pydata/xarray/labels{/name}","releases_url":"https://api.github.com/repos/pydata/xarray/releases{/id}","deployments_url":"https://api.github.com/repos/pydata/xarray/deployments","created_at":"2013-09-30T17:21:10Z","updated_at":"2018-04-29T09:37:36Z","pushed_at":"2018-04-28T20:30:49Z","git_url":"git://github.com/pydata/xarray.git","ssh_url":"git@github.com:pydata/xarray.git","clone_url":"https://github.com/pydata/xarray.git","svn_url":"https://github.com/pydata/xarray","homepage":"http://xarray.pydata.org","size":11846,"stargazers_count":806,"watchers_count":806,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":243,"mirror_url":null,"archived":false,"open_issues_count":456,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":243,"open_issues":456,"watchers":806,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pydata/xarray/pulls/1252"},"html":{"href":"https://github.com/pydata/xarray/pull/1252"},"issue":{"href":"https://api.github.com/repos/pydata/xarray/issues/1252"},"comments":{"href":"https://api.github.com/repos/pydata/xarray/issues/1252/comments"},"review_comments":{"href":"https://api.github.com/repos/pydata/xarray/pulls/1252/comments"},"review_comment":{"href":"https://api.github.com/repos/pydata/xarray/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pydata/xarray/pulls/1252/commits"},"statuses":{"href":"https://api.github.com/repos/pydata/xarray/statuses/ca4d7ddb4001e6c0615aac069471a411a4c64418"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"shoyer"}}