{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/13965","repository_url":"https://api.github.com/repos/pydata/pandas","labels_url":"https://api.github.com/repos/pydata/pandas/issues/13965/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/13965/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/13965/events","html_url":"https://github.com/pydata/pandas/issues/13965","id":170679944,"number":13965,"title":"Exact matches in time-based .rolling()","user":{"login":"chrisaycock","id":453745,"avatar_url":"https://avatars.githubusercontent.com/u/453745?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisaycock","html_url":"https://github.com/chrisaycock","followers_url":"https://api.github.com/users/chrisaycock/followers","following_url":"https://api.github.com/users/chrisaycock/following{/other_user}","gists_url":"https://api.github.com/users/chrisaycock/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisaycock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisaycock/subscriptions","organizations_url":"https://api.github.com/users/chrisaycock/orgs","repos_url":"https://api.github.com/users/chrisaycock/repos","events_url":"https://api.github.com/users/chrisaycock/events{/privacy}","received_events_url":"https://api.github.com/users/chrisaycock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-11T15:50:49Z","updated_at":"2016-08-11T17:47:34Z","closed_at":null,"body":"I would like to `allow_exact_matches` in time-based `.rolling()`. Using an example similar to the one found in the documentation:\r\n\r\n```\r\ndf = pd.DataFrame({'B': [1, 1, 2, np.nan, 4]},\r\n                  index = [pd.Timestamp('20130101 09:00:00'),\r\n                           pd.Timestamp('20130101 09:00:02'),\r\n                           pd.Timestamp('20130101 09:00:03'),\r\n                           pd.Timestamp('20130101 09:00:05'),\r\n                           pd.Timestamp('20130101 09:00:06')])\r\n```\r\n\r\nI can compute the three-second rolling sum:\r\n\r\n```\r\nIn [200]: df\r\nOut[200]:\r\n                       B\r\n2013-01-01 09:00:00  1.0\r\n2013-01-01 09:00:02  1.0\r\n2013-01-01 09:00:03  2.0\r\n2013-01-01 09:00:05  NaN\r\n2013-01-01 09:00:06  4.0\r\n\r\nIn [201]: df.rolling('3s').sum()\r\nOut[201]:\r\n                       B\r\n2013-01-01 09:00:00  1.0\r\n2013-01-01 09:00:02  2.0\r\n2013-01-01 09:00:03  3.0\r\n2013-01-01 09:00:05  2.0\r\n2013-01-01 09:00:06  4.0\r\n```\r\n\r\nBut note that `09:00:03` does not include `09:00:00`, `09:00:05` does not include `09:00:02`, and `09:00:06` does not include `09:00:03`. If I were to include these timestamps, then I would have:\r\n\r\n```\r\n                       B\r\n2013-01-01 09:00:00  1.0\r\n2013-01-01 09:00:02  2.0\r\n2013-01-01 09:00:03  4.0\r\n2013-01-01 09:00:05  3.0\r\n2013-01-01 09:00:06  6.0\r\n```\r\n\r\nA quick-and-dirty way of getting these values is with:\r\n\r\n```\r\nfrom itertools import starmap\r\n\r\nwindow = pd.Timedelta('3s')\r\n\r\nbegins = np.searchsorted(df.index, df.index - window)\r\nends = np.arange(len(df)) + 1\r\nranges = starmap(range, zip(begins, ends))\r\n\r\npd.concat([df.ix[r].sum() for r in ranges])\r\n```\r\n\r\n`pd.merge_asof()` has the parameter `allow_exact_matches` to permit this. Would it be possible to add this to `.rolling()`?\r\n\r\nI can try this one myself."},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/239236751","html_url":"https://github.com/pydata/pandas/issues/13965#issuecomment-239236751","issue_url":"https://api.github.com/repos/pydata/pandas/issues/13965","id":239236751,"user":{"login":"jorisvandenbossche","id":1020496,"avatar_url":"https://avatars.githubusercontent.com/u/1020496?v=3","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},"created_at":"2016-08-11T17:47:34Z","updated_at":"2016-08-11T17:47:34Z","body":"Agreed with @chris-b1 that it would be a nice addition, but for me `allow_exact_matches` is not a very clear name as well (in the sense that I wouldn't directly think of that use case when I see the name). \r\nI think it is actually about an open vs closed interval? So maybe using `closed=True/False` would also be an option, given that 'right'/'left' is not the correct meaning here (as it is always right closed, and it's only the left that can be open or closed). Although that name is also not directly meaningful from its name alone."}}
{"actor":{"display_login":"jorisvandenbossche"}}