BUG: DatetimeIndex creation with BusinessHour frequency fails when first hour of the day is not included as Timestamp

This issue has been created since 2022-11-22.

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. (confirmed on 1.5.1, 1.5.2 is not yet available on pip)

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
freq = pd.offsets.BusinessHour(start="9:00", end="17:00")
x = pd.DatetimeIndex(["20200106 09:00"], name="time", freq=freq)  # Works
x = pd.DatetimeIndex(["20200106 09:00","20200106 10:00"], name="time", freq=freq) # Works
x = pd.DatetimeIndex(["20200106 10:00"], name="time", freq=freq) # Fails

Issue Description

Creation of DatetimeIndex with BusinessHour frequency fails when the ts_input arg to DatetimeIndex does not start at BusinessHour start time, resulting in the following error:

Traceback (most recent call last):
  File "C:\Users\...\site-packages\pandas\core\arrays\datetimelike.py", line 962, in _validate_frequency
    raise ValueError
ValueError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\...\site-packages\pandas\core\indexes\datetimes.py", line 327, in __new__
    dtarr = DatetimeArray._from_sequence_not_strict(
  File "C:\Users\...\site-packages\pandas\core\arrays\datetimes.py", line 377, in _from_sequence_not_strict
    cls._validate_frequency(result, freq, ambiguous=ambiguous)
  File "C:\Users\...\site-packages\pandas\core\arrays\datetimelike.py", line 973, in _validate_frequency
    raise ValueError(
ValueError: Inferred frequency None from passed values does not conform to passed frequency BH

Expected Behavior

Returns the specified Timestamp without error.

Installed Versions

INSTALLED VERSIONS

commit : e8093ba
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 167 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : German_Austria.1252

pandas : 1.4.3
numpy : 1.22.4
pytz : 2022.4
dateutil : 2.8.2
setuptools : 59.8.0
pip : 22.2.2
Cython : 0.29.32
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.4
jinja2 : None
IPython : 8.5.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.8.2
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.6.0
numba : 0.56.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : 1.4.41
tables : None
tabulate : None
xarray : 2022.9.0
xlrd : None
xlwt : None
zstandard : None

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-12-07
Star Count 36168
Watcher Count 1118
Fork Count 15472
Issue Count 3683

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[Bug] Cursor showing on the wrong letter on chrome 2 2020-02-11 2022-12-04
Open in iframe setting per search target 4 2021-02-26 2022-11-25
Не используется зеркало hub.oscript.ru 5 2022-03-21 2022-09-27
Декларативное определение библиотеки на основе структуры проекта 4 2022-04-22 2022-09-27
Не устанавливается vrunner ubuntu 18 1 2022-02-17 2022-09-27
read-line not prompts in loop 4 2022-06-08 2022-09-15
能请教下授权服务器的配置么 0 2021-04-30 2022-01-08
Checking model instances are not types 1 2022-06-09 2022-12-05
Missing word before comma in first line second sentance of https://docs.microsoft.com/en-us/appcenter/test-cloud/frameworks/uitest/features/webviews#invoking-javascript 0 2021-04-19 2022-11-23
scanner doesn't understand go 1.13 number syntax 4 2022-03-16 2022-11-27
[Bug]: E518: Unknown option: separator_style Press ENTER or type command to continue 5 2022-08-14 2022-12-05
It reported an error,when i pressed the 'w' key 3 2022-03-17 2022-11-12
[ bug ]使用Oracle查询的时候必须制定列名 2 2021-07-27 2022-11-19
请问你们数据库的结构图是用什么工具做的 5 2021-09-10 2022-01-16
Support for Govcloud? 5 2021-04-07 2022-11-06
[MeshingApplication] Non thread-safe metric operations? 7 2021-09-03 2022-10-16
error: static assertion failed: Specified Data Type not supported 1 2021-09-20 2022-10-24
Shows warning for text-decoration-color property as unknown property. 0 2021-02-12 2022-05-05
Jupyter Lab not launching 7 2021-11-17 2022-09-20
windows10下输入中文字符后光标前移到输入内容的倒数第一个字前 2 2022-02-28 2022-11-05
Package updates for the month of November 0 2022-11-07 2022-12-06
Replace youtube-dl with yt-dlp system-wide 2 2021-10-17 2022-09-12
Sidecar (1.2.2-feee67c) stuck 1 2022-02-12 2022-11-09
`encoding.only_fields` doesn't drop fields with special characters 1 2022-06-21 2022-11-27
ERROR: SQL Failed! Error:'1582' 19 2022-07-19 2022-12-05
Synergic use of deep linking with multi-diagram plugin 0 2022-03-18 2022-03-15
Deduct "Specific Status" Orders Amount From Woocommerce Analytics and Show that Amount on Woocommerce Overview and Revenue Section 7 2022-02-22 2022-02-28
feat:自动更新官网 star 数,贡献者,下载量 1 2021-11-09 2022-01-14
Infra - 压缩静态资源(图片)体积、加速内容渲染 0 2021-10-14 2022-01-15
Firmware updates fail for Aqara Curtain Motor E1 (ZNCLBL01LM) by Xiaomi 5 2022-09-01 2022-09-02
[New device support]: Sylvania 73742 Variant (LEDVANCE RT TW) 1 2022-09-01 2022-09-02
[Bug] Created user directories is owned by root, and not the user 43 2022-02-01 2022-12-05
如何在大量的数据中找出不重复的整数? 1 2021-09-21 2022-01-16
[auto-generated] Exception in plugin 0 2021-09-13 2022-07-27
[Dashboard] Inject storage-type attribute for PVC storage strategy configuration 0 2022-09-08 2022-10-22
Write integration test to check the extrinsic index on Kusama 0 2021-10-06 2022-11-18
Add a sensible fallback for permalink :filename when not backed by a file 1 2022-01-31 2022-10-19
Insecure direct object references(IDOR) bug 3 2021-01-22 2022-10-20
Hashmap doesn't seem to get uninstalled correct 3 2017-10-28 2022-10-20
I got an issues "Error: NoSuchMethodError: method not found: 'isTTY' on null" 4 2021-12-02 2022-11-18
Need better docs 6 2020-06-15 2022-01-10
Linking static MKL libraries 2 2020-06-08 2022-10-31
redux-saga源码学习 0 2021-01-23 2022-01-23
ppstructure分析的结果,保存切片图片时,如何矫正图片?好像bbox只有左上和右下2个坐标,缺少右上和坐下2个坐标,没法矫正? 1 2022-10-07 2022-10-19
Background image in HEADER is not responsive 1 2020-09-14 2022-11-15
Process memory scanning additions 0 2021-08-27 2022-09-11
Nier Automata fails to launch 0 2021-12-05 2022-11-27
retryCondition calling a healthcheck api 2 2022-02-17 2022-11-14
kafapache Kafka client 0 2021-12-15 2022-11-03
Icons filesize 0 2017-12-18 2022-01-13