Skip to content

BUG: freq attribute sometimes lost when concatenating series that are tz-aware #35414

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 Jul 26, 2020 · 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

s1 = pd.Series([1, 2, 3], index=pd.date_range('2020-03-29 00:00:00', periods=3, freq='D', tz='Europe/Berlin'))
s2 = pd.Series([4, 5], pd.date_range(s1.index[-1]+s1.index.freq, periods=2, freq=s1.index.freq))
r = pd.concat([s1, s2])

s1.index, s2.index, r.index
 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'],
               dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 DatetimeIndex(['2020-04-01 00:00:00+02:00', '2020-04-02 00:00:00+02:00'], dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 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',
                '2020-04-02 00:00:00+02:00'],
               dtype='datetime64[ns, Europe/Berlin]', freq=None)

Problem description

s1 and s2 have indices are in the same time zone with the same fixed frequency. This also hold when they are concatenated, however, the freq attribute is lost in the result, see above. Expected would be, to have freq='D'.

The problem does not always occur.

  • When the DST change is not included, it seems to work:
  #Same code, change 2020-03-29 to 2020-03-01
 DatetimeIndex(['2020-03-01 00:00:00+01:00', '2020-03-02 00:00:00+01:00',
                '2020-03-03 00:00:00+01:00'],
               dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 DatetimeIndex(['2020-03-04 00:00:00+01:00', '2020-03-05 00:00:00+01:00'], dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 DatetimeIndex(['2020-03-01 00:00:00+01:00', '2020-03-02 00:00:00+01:00',
                '2020-03-03 00:00:00+01:00', '2020-03-04 00:00:00+01:00',
                '2020-03-05 00:00:00+01:00'],
               dtype='datetime64[ns, Europe/Berlin]', freq='D')
  • When DST is included incorrectly (see here), and all timestamps are 24h apart, it also works:
  #Same code, change 2020-03-29 to 2020-03-27
 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'],
               dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 DatetimeIndex(['2020-03-30 01:00:00+02:00', '2020-03-31 01:00:00+02:00'], dtype='datetime64[ns, Europe/Berlin]', freq='D'),
 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 01:00:00+02:00',
                '2020-03-31 01:00:00+02:00'],
               dtype='datetime64[ns, Europe/Berlin]', freq='D')

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas : 1.0.5
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200714
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : 1.3.18
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None

@rwijtvliet rwijtvliet added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 26, 2020
@jbrockmendel
Copy link
Member

I can't reproduce this on master. Can you confirm?

@TomAugspurger
Copy link
Contributor

Also can't reproduce. Let us know if you still see it on master @rwijtvliet.

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