Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1, 2]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000","1969-06-01 02:01:00.000000001"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
This outputs
col_first col_count
1969-06-01 1 2
Issue Description
The bucket starting at 1969-06-01
should not include the first row from the dataframe. The index is 1969-06-01 00:00:00.000000000
and closed is right
which means that the value is on the opened boundary thus it does not fall into the bucket.
Moreover if the second row is removed we get
import pandas as pd
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
Which outputs: ``` col_first col_count 1969-05-31 22:21:05 1 1
### Expected Behavior
```python
import pandas as pd
from pandas import Timedelta, Timestamp
df = pd.DataFrame({"col": [1, 2]}, index=pd.to_datetime(["1969-06-01 00:00:00.000000000","1969-06-01 02:01:00.000000001"]))
rule = "7315s"
offset = pd.Timedelta("23min")
df.resample(rule, origin="end_day", offset=offset, closed="right", label="left").agg(None, col_first=("col", "first"), col_count=("col", "count"))
The first row should not be part of the bucket. It's part of the bucket starting at 1969-05-31 22:21:05
but as this is before the first value of the dataframe that bucket is not created.
col_first col_count
1969-06-01 2 1
Installed Versions
Comment From: Nikhil-Narayanan
take