Skip to content

BUG: DateTimeIndex + DateTimeIndex.freq giving incorrect result if timezone is set. #39398

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

Closed
2 of 3 tasks
rwijtvliet opened this issue Jan 25, 2021 · 2 comments
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@rwijtvliet
Copy link

  • 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

import pandas as pd
i = pd.date_range('2020-03-27', freq='D', periods=4, tz='Europe/Berlin')
i2 = i + i.freq
i2.freq = 'D' # ValueError: Inferred frequency None from passed values does not conform to passed frequency D

Problem description

i is as expected.

DatetimeIndex(['2020-03-27 00:00:00+01:00', '2020-03-28 00:00:00+01:00',
               '2020-03-29 00:00:00+01:00', '2020-03-30 00:00:00+02:00'],
              dtype='datetime64[ns, Europe/Berlin]', freq='D') #good

but i2 has two issues:

DatetimeIndex(['2020-03-29 00:00:00+01:00', '2020-03-30 01:00:00+02:00',
               '2020-03-31 00:00:00+02:00', '2020-04-01 00:00:00+02:00'],
              dtype='datetime64[ns, Europe/Berlin]', freq='D') 
#issue: 2020-03-30 timestamp not at midnight
#issue: i2 has attribute `freq='D'`, but pd.infer_freq returns None

Expected Output

i2 to be

DatetimeIndex(['2020-03-29 00:00:00+01:00', '2020-03-30 00:00:00+02:00',
               '2020-03-31 00:00:00+02:00', '2020-04-01 00:00:00+02:00'],
              dtype='datetime64[ns, Europe/Berlin]', freq='D') 

(2020-03-30 00:00:00+02:00 is only change),
with i2.freq not returning None

Related

May be related to #38243

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : de_DE.cp1252

pandas : 1.2.0
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.2.post20210112
Cython : None
pytest : 6.2.1
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : 1.3.22
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@rwijtvliet rwijtvliet added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2021
@rwijtvliet rwijtvliet changed the title BUG: freq BUG: DateTimeIndex + DateTimeIndex.freq giving incorrect result if timezone is set. Jan 25, 2021
@phofl
Copy link
Member

phofl commented Jan 25, 2021

This addition is done in nanoseconds, so this is expected because of the change of time there. But not sure if this is intended.

The second error is correct, since your freq is no longer D

@mroeschke
Copy link
Member

Yes this is currently the expected behavior in both cases. But we're aiming to return the midnight result eventually #22864

So going to close this issue as the expected behavior, but happy to have efforts changing D to mean "calendar day"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants