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
BUG: Regression adding Timedelta to DatetimeIndex, get ValueError: Inferred frequency None from passed values does not conform to passed frequency
#37295
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.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/.miniconda/lib/python3.7/site-packages/pandas/core/arrays/datetimelike.py in _validate_frequency(cls, index, freq, **kwargs)
1156 if not np.array_equal(index.asi8, on_freq.asi8):
-> 1157 raise ValueError
1158 except ValueError as e:
ValueError:
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-2-d8f454fa3ee3> in <module>
----> 1 pd.date_range(start=pd.Timestamp('2019-03-26 00:00:00-0400', tz='Canada/Eastern'), end=pd.Timestamp('2020-10-17 00:00:00-0400', tz='Canada/Eastern'), freq='D') + pd.Timedelta('1D')
~/.miniconda/lib/python3.7/site-packages/pandas/core/indexes/extension.py in method(self, other)
145returnNotImplemented146 meth =getattr(self._data, opname)
--> 147 result = meth(_maybe_unwrap_index(other))
148return _wrap_arithmetic_op(self, other, result)
149
~/.miniconda/lib/python3.7/site-packages/pandas/core/ops/common.py in new_method(self, other)
63 other = item_from_zerodim(other)
64
---> 65 return method(self, other)
6667return new_method
~/.miniconda/lib/python3.7/site-packages/pandas/core/arrays/datetimelike.py in __add__(self, other)
1399 result = self._add_nat()
1400 elif isinstance(other, (Tick, timedelta, np.timedelta64)):
-> 1401 result = self._add_timedeltalike_scalar(other)
1402 elif isinstance(other, BaseOffset):
1403 # specifically _not_ a Tick
~/.miniconda/lib/python3.7/site-packages/pandas/core/arrays/datetimelike.py in _add_timedeltalike_scalar(self, other)
1254 new_freq = self.freq
1255
-> 1256 return type(self)(new_values, dtype=self.dtype, freq=new_freq)
1257
1258 def _add_timedelta_arraylike(self, other):
~/.miniconda/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py in __init__(self, values, dtype, freq, copy)
282283if inferred_freq isNoneand freq isnotNone:
--> 284 type(self)._validate_frequency(self, freq)
285286@classmethod
~/.miniconda/lib/python3.7/site-packages/pandas/core/arrays/datetimelike.py in _validate_frequency(cls, index, freq, **kwargs)
1169 f"Inferred frequency {inferred} from passed values "
1170 f"does not conform to passed frequency {freq.freqstr}"
-> 1171 ) from e
1172
1173 # monotonicity/uniqueness properties are called via frequencies.infer_freq,
ValueError: Inferred frequency None from passed values does not conform to passed frequency D
Problem description
Unexpected ValueError when adding a Timedelta to a timezone-aware DatetimeIndex. It appears using timezone-aware Timestamp objects is necessary to reproduce - simple date strings won't.
Expected Output
The output from the same code sample in v0.25.3 is:
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Traceback
Problem description
Unexpected ValueError when adding a Timedelta to a timezone-aware DatetimeIndex. It appears using timezone-aware Timestamp objects is necessary to reproduce - simple date strings won't.
Expected Output
The output from the same code sample in
v0.25.3
is:don't know about later versions, before
v1.1.3
.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.7.6.final.0
python-bits : 64
OS : Darwin
OS-release : 16.7.0
Version : Darwin Kernel Version 16.7.0: Thu Dec 20 21:53:35 PST 2018; root:xnu-3789.73.31~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_CA.UTF-8
LOCALE : en_CA.UTF-8
pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 50.3.0
Cython : 0.29.20
pytest : 6.1.1
hypothesis : None
sphinx : 1.8.5
blosc : 1.9.2
feather : None
xlsxwriter : 1.2.1
lxml.etree : 4.5.2
html5lib : 0.9999999
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: 0.9.0
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 2.6.3
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.11
tables : 3.6.1
tabulate : None
xarray : 0.16.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.51.2
The text was updated successfully, but these errors were encountered: