Open
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
import pandas as pd
idx = pd.date_range(
start='2021-04-22 01:00:00+00:00',
end='2021-04-28 01:00:00+00:00',
freq='1d'
)
df = pd.DataFrame(index=idx, data=range(len(idx)))
result = df.resample(rule='7d', origin='end_day').min()
Issue Description
Using origin='end_day'
when resampling raises a ValueError. I don't understand the error message.
Traceback
Traceback (most recent call last):
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-28-b959ed20b9fd>", line 11, in <module>
result = df.resample(rule='7d', origin='end_day').min()
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\frame.py", line 10350, in resample
return super().resample(
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\generic.py", line 8126, in resample
return get_resampler(
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 1382, in get_resampler
return tg._get_resampler(obj, kind=kind)
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 1552, in _get_resampler
return DatetimeIndexResampler(obj, groupby=self, kind=kind, axis=self.axis)
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 158, in __init__
self.binner, self.grouper = self._get_binner()
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 241, in _get_binner
binner, bins, binlabels = self._get_binner_for_time()
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 1113, in _get_binner_for_time
return self.groupby._get_time_bins(self.ax)
File "C:\Users\User.Name\.virtualenvs\MyEnv-SwK0JD0-\lib\site-packages\pandas\core\resample.py", line 1609, in _get_time_bins
bins = lib.generate_bins_dt64(
File "pandas\_libs\lib.pyx", line 809, in pandas._libs.lib.generate_bins_dt64
ValueError: Values falls before first bin
Expected Behavior
The resample docs say
‘end_day’: origin is the ceiling midnight of the last day
so I expected origin='end_day'
to behave like origin=df.index.max().ceil('1d')
.
However, only the first approach raises an error.
>>> df.resample(rule='7d', origin=df.index.max().ceil('1d')).min()
0
2021-04-22 00:00:00+00:00 0
Installed Versions
INSTALLED VERSIONS
------------------
commit : 66e3805
python : 3.8.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.5
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.0.1
setuptools : 53.0.0
Cython : None
pytest : 6.2.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.2 (dt dec pq3 ext lo64)
jinja2 : 3.0.3
IPython : 7.30.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.28
tables : None
tabulate : 0.8.9
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None
------------------
commit : 66e3805
python : 3.8.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.5
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.0.1
setuptools : 53.0.0
Cython : None
pytest : 6.2.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.2 (dt dec pq3 ext lo64)
jinja2 : 3.0.3
IPython : 7.30.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.28
tables : None
tabulate : 0.8.9
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None