Description
Code Sample
df = pd.DataFrame()
date1 = pd.Timestamp('20190101', tz='Europe/Brussels')
date2 = pd.Timestamp('20190201T00:00:00+01:00')
df.truncate(before=date1, after=date2)
File "/python3.7/site-packages/pandas/core/indexes/base.py", line 5244, in slice_locs
raise ValueError("Both dates must have the " "same UTC offset")
ValueError: Both dates must have the same UTC offset
Problem description
In #25263, these lines were added (line 4881):
if not tz_compare(ts_start.tzinfo, ts_end.tzinfo):
raise ValueError("Both dates must have the same UTC offset"
- The timestamps in the example do have the same UTC offset. The difference is that one has an actual timezone, while the other has a fixed offset. So a simple comparison of
tzinfo
is insufficient here. - It is unclear to my why you shouldn't be able to truncate with timestamps with different offsets!?
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.6.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.3
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.2.1
setuptools : 28.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : 4.7.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.3.3
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : 1.3.3
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None