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.

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

Reproducible Example

import pandas as pd
import numpy as np

index = pd.TimedeltaIndex([np.timedelta64(1, "D")], freq="d", name="foo")

Issue Description

A ValueError is raised when creating a TimedeltaIndex from a provided array of np.timedelta64.

This happens on main branch of Pandas, but not with the latest released version 1.5.3.

file test.py:

import pandas as pd
import numpy as np

index = pd.TimedeltaIndex([np.timedelta64(1, "D")], freq="d", name="foo")

running:

> python test.py
Traceback (most recent call last):
  File "/Users/jbennet/mambaforge/envs/dask-ci/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 1908, in _validate_frequency
    raise ValueError
ValueError

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

Traceback (most recent call last):
  File "/Users/jbennet/src/dask/test.py", line 4, in <module>
    index = pd.TimedeltaIndex([np.timedelta64(1, "D")], freq="d", name="foo")
  File "/Users/jbennet/mambaforge/envs/dask-ci/lib/python3.10/site-packages/pandas/core/indexes/timedeltas.py", line 161, in __new__
    tdarr = TimedeltaArray._from_sequence_not_strict(
  File "/Users/jbennet/mambaforge/envs/dask-ci/lib/python3.10/site-packages/pandas/core/arrays/timedeltas.py", line 252, in _from_sequence_not_strict
    cls._validate_frequency(result, freq)
  File "/Users/jbennet/mambaforge/envs/dask-ci/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 1919, in _validate_frequency
    raise ValueError(
ValueError: Inferred frequency None from passed values does not conform to passed frequency D

Expected Behavior

Expected to not raise an exception.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 7cb7592523380133f552e258f272a5694e37957a python : 3.10.8.final.0 python-bits : 64 OS : Darwin OS-release : 22.2.0 Version : Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.0.0.dev0+1147.g7cb7592523 numpy : 1.25.0.dev0+405.g720cabc23 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 66.0.0 pip : 22.3.1 Cython : None pytest : 7.2.1 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.8.0 pandas_datareader: None bs4 : None bottleneck : None brotli : fastparquet : 2022.12.1.dev8 fsspec : 2022.11.0+27.gb4661bb gcsfs : None matplotlib : None numba : None numexpr : 2.8.3 odfpy : None openpyxl : None pandas_gbq : None pyarrow : 10.0.1 pyreadstat : None pyxlsb : None s3fs : 2022.11.0+10.g8c7dfd4 scipy : 1.11.0.dev0+0.d5d04ef snappy : sqlalchemy : 1.4.46 tables : 3.7.0 tabulate : None xarray : 2022.12.0 xlrd : None zstandard : None tzdata : None qtpy : None pyqt5 : None

Comment From: jbrockmendel

can you try this on main? this works for me.

Comment From: j-bennet

Sorry, this was not main, but a nightly conda build, installed with:

python -m pip install --no-deps -i https://pypi.anaconda.org/scipy-wheels-nightly/simple pandas

Comment From: j-bennet

Can't reproduce the error on main, closing.