Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: unable to generate daily business frequency data #60596

Open
2 of 3 tasks
ngupta23 opened this issue Dec 20, 2024 · 1 comment
Open
2 of 3 tasks

BUG: unable to generate daily business frequency data #60596

ngupta23 opened this issue Dec 20, 2024 · 1 comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ngupta23
Copy link

ngupta23 commented Dec 20, 2024

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 main branch of pandas.

Reproducible Example

import pandas as pd
pd.date_range('2000-01-03 00:00:00', freq=pd.offsets.BusinessHour(start='00:00', end='23:59'), periods=25)

DatetimeIndex(['2000-01-03 00:00:00', '2000-01-03 01:00:00',
               '2000-01-03 02:00:00', '2000-01-03 03:00:00',
               '2000-01-03 04:00:00', '2000-01-03 05:00:00',
               '2000-01-03 06:00:00', '2000-01-03 07:00:00',
               '2000-01-03 08:00:00', '2000-01-03 09:00:00',
               '2000-01-03 10:00:00', '2000-01-03 11:00:00',
               '2000-01-03 12:00:00', '2000-01-03 13:00:00',
               '2000-01-03 14:00:00', '2000-01-03 15:00:00',
               '2000-01-03 16:00:00', '2000-01-03 17:00:00',
               '2000-01-03 18:00:00', '2000-01-03 19:00:00',
               '2000-01-03 20:00:00', '2000-01-03 21:00:00',
               '2000-01-03 22:00:00', '2000-01-03 23:00:00',
               '2000-01-04 00:01:00'],
              dtype='datetime64[ns]', freq='BH')

Issue Description

I have a time series dataset that produces data every hour from Monday to Friday and no data on Saturday and Sunday. I am unable to create these time stamps using pd.offsets.BusinessHour. There is an issue with the crossover between days. As you can see above, the timestamp 2000-01-04 00:00:00 is completely missing.

If this is not a bug, could anyone please let me know how to produce these time indices.

Expected Behavior

DatetimeIndex(['2000-01-03 00:00:00', '2000-01-03 01:00:00',
               '2000-01-03 02:00:00', '2000-01-03 03:00:00',
               '2000-01-03 04:00:00', '2000-01-03 05:00:00',
               '2000-01-03 06:00:00', '2000-01-03 07:00:00',
               '2000-01-03 08:00:00', '2000-01-03 09:00:00',
               '2000-01-03 10:00:00', '2000-01-03 11:00:00',
               '2000-01-03 12:00:00', '2000-01-03 13:00:00',
               '2000-01-03 14:00:00', '2000-01-03 15:00:00',
               '2000-01-03 16:00:00', '2000-01-03 17:00:00',
               '2000-01-03 18:00:00', '2000-01-03 19:00:00',
               '2000-01-03 20:00:00', '2000-01-03 21:00:00',
               '2000-01-03 22:00:00', '2000-01-03 23:00:00',
               '2000-01-04 00:00:00'],
              dtype='datetime64[ns]', freq='BH')

Timestamp '2000-01-04 00:00:00' should be present.

Installed Versions

INSTALLED VERSIONS

commit : a671b5a
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.146.1-microsoft-standard-WSL2
Version : #1 SMP Thu Jan 11 04:09:03 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.1.4
numpy : 1.26.4
pytz : 2024.2
dateutil : 2.9.0.post0
setuptools : 69.5.1
pip : None
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.30.0
pandas_datareader : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : 2024.12.0
gcsfs : None
matplotlib : 3.10.0
numba : 0.60.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 18.1.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : 2.0.36
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : 0.23.0
tzdata : 2024.2
qtpy : None
pyqt5 : None

@ngupta23 ngupta23 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 20, 2024
@Liam3851
Copy link
Contributor

BusinessHour is primarily for finding business hours within a day (say, 09:00 to 17:00). It is not particularly for holiday applications.

For your purposes try

import pandas as pd
start_date = '2000-01-01'
end_date = '2023-12-23'
# create an hourly date range
dr = pd.date_range(start_date, end_date, freq='H')
# limit to business days
dr = dr[dr.weekday <= 4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants