Skip to content

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

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

Closed
3 tasks done
DavidKleindienst opened this issue Nov 22, 2022 · 3 comments · Fixed by #50530
Assignees
Labels
Bug Datetime Datetime data dtype Index Related to the Index class or subclasses

Comments

@DavidKleindienst
Copy link
Contributor

DavidKleindienst commented Nov 22, 2022

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

@DavidKleindienst DavidKleindienst added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 22, 2022
@DavidKleindienst DavidKleindienst changed the title BUG: BUG: DatetimeIndex creation with BusinessHour frequency fails when first hour of the day is not included as Timestamp Nov 22, 2022
@mshah0722
Copy link

take

@phofl phofl added Datetime Datetime data dtype Index Related to the Index class or subclasses and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 5, 2022
@DavidKleindienst
Copy link
Contributor Author

@mshah0722 would you mind me having a go at this as well?

@mshah0722 mshah0722 removed their assignment Dec 28, 2022
@DavidKleindienst
Copy link
Contributor Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants