You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
In [1]: DatetimeIndex(date_range('2000', periods=2).as_unit('s').normalize(), freq='D')
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
File~/pandas-dev/pandas/core/arrays/datetimelike.py:1912, inTimelikeOps._validate_frequency(cls, index, freq, **kwargs)
1911ifnotnp.array_equal(index.asi8, on_freq.asi8):
->1912raiseValueError1913exceptValueErroraserr:
ValueError:
Theaboveexceptionwasthedirectcauseofthefollowingexception:
ValueErrorTraceback (mostrecentcalllast)
CellIn[1], line1---->1DatetimeIndex(date_range('2000', periods=2).as_unit('s').normalize(), freq='D')
File~/pandas-dev/pandas/core/indexes/datetimes.py:335, inDatetimeIndex.__new__(cls, data, freq, tz, normalize, closed, ambiguous, dayfirst, yearfirst, dtype, copy, name)
332data=data.copy()
333returncls._simple_new(data, name=name)
-->335dtarr=DatetimeArray._from_sequence_not_strict(
336data,
337dtype=dtype,
338copy=copy,
339tz=tz,
340freq=freq,
341dayfirst=dayfirst,
342yearfirst=yearfirst,
343ambiguous=ambiguous,
344 )
346subarr=cls._simple_new(dtarr, name=name)
347returnsubarrFile~/pandas-dev/pandas/core/arrays/datetimes.py:360, inDatetimeArray._from_sequence_not_strict(cls, data, dtype, copy, tz, freq, dayfirst, yearfirst, ambiguous)
356result=result.as_unit(unit)
358ifinferred_freqisNoneandfreqisnotNone:
359# this condition precludes `freq_infer`-->360cls._validate_frequency(result, freq, ambiguous=ambiguous)
362eliffreq_infer:
363# Set _freq directly to bypass duplicative _validate_frequency364# check.365result._freq=to_offset(result.inferred_freq)
File~/pandas-dev/pandas/core/arrays/datetimelike.py:1923, inTimelikeOps._validate_frequency(cls, index, freq, **kwargs)
1917raiseerr1918# GH#11587 the main way this is reached is if the `np.array_equal`1919# check above is False. This can also be reached if index[0]1920# is `NaT`, in which case the call to `cls._generate_range` will1921# raise a ValueError, which we re-raise with a more targeted1922# message.->1923raiseValueError(
1924f"Inferred frequency {inferred} from passed values "1925f"does not conform to passed frequency {freq.freqstr}"1926 ) fromerrValueError: InferredfrequencyNonefrompassedvaluesdoesnotconformtopassedfrequencyDIn [2]: DatetimeIndex(date_range('2000', periods=2).as_unit('ns').normalize(), freq='D')
Out[2]: DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq='D')
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
Issue Description
I don't think the first case should raise?
Expected Behavior
Installed Versions
INSTALLED VERSIONS
commit : 954cf55
python : 3.11.1.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.102.1-microsoft-standard-WSL2
Version : #1 SMP Wed Mar 2 00:30:59 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 2.0.0.dev0+1168.g954cf55938
numpy : 1.24.1
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.7.0
pip : 22.3.1
Cython : 0.29.33
pytest : 7.2.0
hypothesis : 6.52.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None
None
The text was updated successfully, but these errors were encountered: