Closed zljubisic closed 1 year ago
d = dt.datetime(2023,4,1).replace(tzinfo=pytz.timezone(tz))
This is incorrect usage of pytz timezones. You'll need to use pytz.timezone(tz).localize(dt.datetime(...))
instead to get the correct date. Closing as a usage question
@mroeschke You are right. If I use pytz as you have suggested, everything works as expected. Thank you very much, and best regards.
PS Stupid chatgpt4
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.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
If I create a
date_range()
with tz aware datetime instead of time2023-04-01 00:00:00+02:00
as a firstidx
element I get2023-04-01 01:07:00+02:00
. From where this01:07:00+02:00
showed up?If
date_range()
is created from tz naive datetime, and than later ontz_localize
-d, everything works as expected.Expected Behavior
I believe that
date_range()
shouldn't change the very first element ofidx
, so it should be2023-04-01 00:00:00+02:00
. This shows correct result:pd.date_range(start=dt.datetime(2023,4,1), periods=10, freq='H', tz="Europe/Stockholm")
(start is not tz aware, but tz is specified)Installed Versions
INSTALLED VERSIONS
commit : 478d340667831908b5b4bf09a2787a11a14560c9 python : 3.8.3.final.0 python-bits : 64 OS : Linux OS-release : 3.10.0-1127.el7.x86_64 Version : #1 SMP Tue Mar 31 23:36:51 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : None.None
pandas : 2.0.0 numpy : 1.24.2 pytz : 2023.3 dateutil : 2.8.2 setuptools : 61.2.0 pip : 21.2.4 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None 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 : 2023.3 qtpy : None pyqt5 : None