Skip to content
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.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DatetimeIndex.tz_convert() has incorrcect .freq attribute #49696

Open
2 of 3 tasks
rwijtvliet opened this issue Nov 14, 2022 · 3 comments
Open
2 of 3 tasks

BUG: DatetimeIndex.tz_convert() has incorrcect .freq attribute #49696

rwijtvliet opened this issue Nov 14, 2022 · 3 comments
Assignees
Labels
Bug freq retention User expects "freq" attribute to be preserved Frequency DateOffsets Index Related to the Index class or subclasses

Comments

@rwijtvliet
Copy link

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

import pandas as pd

# DST-transition. Frequency is days, because all timestamps are at same time - even if not all days span 24h. So far, so good.
i = pd.date_range('2020-03-27 06:00', freq='D', periods=5, tz='Europe/Berlin')
# DatetimeIndex(['2020-03-27 06:00:00+01:00', '2020-03-28 06:00:00+01:00',
#                '2020-03-29 06:00:00+02:00', '2020-03-30 06:00:00+02:00',
#                '2020-03-31 06:00:00+02:00'],
#               dtype='datetime64[ns, Europe/Berlin]', freq='D')

# Converting to other timezone gives timestamps with distinct times. This index should no longer have the daily frequency. However: it is initially given this frequency nonetheless (=Bug).
i2 = i.tz_convert('UTC')
# DatetimeIndex(['2020-03-27 05:00:00+00:00', '2020-03-28 05:00:00+00:00',
#                '2020-03-29 04:00:00+00:00', '2020-03-30 04:00:00+00:00',
#                '2020-03-31 04:00:00+00:00'],
#               dtype='datetime64[ns, UTC]', freq='D')

# We can confirm that this is incorrect, by manually trying to set the `.freq` attribute:
i2.freq = i2.freq #ValueError: Inferred frequency None from passed values does not conform to passed frequency D

Issue Description

See inline comments.

Expected Behavior

i2 should not have a frequency attribute set.

Installed Versions

INSTALLED VERSIONS

commit : 91111fd
python : 3.9.13.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252

pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.2.2
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
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
xlwt : None
zstandard : None
tzdata : None

@rwijtvliet rwijtvliet added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 14, 2022
@rhshadrach rhshadrach added Frequency DateOffsets Index Related to the Index class or subclasses datetime.date stdlib datetime.date support labels Nov 17, 2022
@jbrockmendel jbrockmendel removed the datetime.date stdlib datetime.date support label Mar 22, 2023
@topper-123 topper-123 removed the Needs Triage Issue that has not been reviewed by a pandas team member label May 21, 2023
@Detoro
Copy link
Contributor

Detoro commented Aug 9, 2023

take

@keelancosgrove
Copy link

hi @rwijtvliet , the frequency attribute was set as part of this issue #25241 - why do you think it should not be set in tz_convert?

@rwijtvliet
Copy link
Author

Hey @keelancosgrove, in the example above, i2 contains timestamps that are on consequtive days, but not at the same time on those days - which is be necessary for them to be "1 day" apart (in my opinion). Therefore, in this case the frequency for i2 should no longer be "day".

@jbrockmendel jbrockmendel added the freq retention User expects "freq" attribute to be preserved label Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug freq retention User expects "freq" attribute to be preserved Frequency DateOffsets Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants