Skip to content

BUG: DateOffset applied to DatetimeIndex losing freq starting in v1.1.0 #39097

Closed
@bexer

Description

@bexer
  • 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

dtsa = pd.date_range('1998', periods = 3, freq = 'A')
s1 = pd.Series([4,5,6], index=dtsa)
s1.index
# DatetimeIndex(['1998-12-31', '1999-12-31', '2000-12-31'], dtype='datetime64[ns]', freq='A-DEC')

i1 = s1.index + pd.DateOffset(years=-1, days=1)
i1
# DatetimeIndex(['1998-01-01', '1999-01-01', '2000-01-01'], dtype='datetime64[ns]', freq=None)

Problem description

I expected i1 to have the frequency "AS-JAN" instead of None. This behavior existed prior to version 1.1.0. For example, in 1.0.5 the output of the same commands is:

> DatetimeIndex(['1998-01-01', '1999-01-01', '2000-01-01'], dtype='datetime64[ns]', freq='AS-JAN')

Expected Output

> DatetimeIndex(['1998-01-01', '1999-01-01', '2000-01-01'], dtype='datetime64[ns]', freq='AS-JAN')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.8.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17134
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.1.0
numpy : 1.19.2
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.0.0.post20201207
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions