BUG: pandas Timestamp tz_localize and tz_convert do not preserve freq attribute · Issue #25241 · pandas-dev/pandas (original) (raw)

The pandas.Timestamp.tz_localize() and pandas.Timestamp.tz_convert() methods do not preserve the freq attribute. For background, the freq attribute is mostly a "helpful label", and it seems semantically ill-defined to me; cf. issue #15146, which proposes removing the attribute.

Code Sample

>>> import pandas
>>> import pytz

>>> t1 = pandas.Timestamp('2019-01-01 10:00', freq='H')
>>> print(t1.tz_localize(pytz.utc).freq)  
None

>>> t2 = pandas.Timestamp('2019-01-02 12:00', tz=pytz.utc, freq='T')
>>> print(t2.tz_convert(pytz.utc).freq)
None

Problem description

I don't think that pandas.Timestamp should actually have a freq attribute, but so long as it does, it should be propagated to the new timestamp value returned by tz_localize() or tz_convert. In the tz_convert case, the method should produce an "equivalent" timestamp with a different tz.

Expected Output

t1.tz_localize(pytz.utc).freq should equal t1.freq, and t2.tz_convert(pytz.utc).freq should equal t2.freq.

Output of pd.show_versions()

No module named 'dask'

INSTALLED VERSIONS

commit: 04df22f
python: 3.7.2.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.25.0.dev0+89.g04df22fbe
pytest: 4.2.0
pip: 19.0.1
setuptools: 40.7.3
Cython: 0.29.4
numpy: 1.15.4
scipy: 1.2.0
pyarrow: 0.11.1
xarray: 0.11.0
IPython: 7.2.0
sphinx: 1.8.4
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.14
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml.etree: 4.3.0
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.2.17
pymysql: 0.9.3
psycopg2: None
jinja2: 2.10
s3fs: 0.2.0
fastparquet: 0.2.1
pandas_gbq: None
pandas_datareader: None
gcsfs: 0.1.2