Description
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
pd.period_range("2020", periods=2, freq="M").to_timestamp(to_offset("ME"))
# Outputs DatetimeIndex(['2020-01-31', '2020-02-29'], dtype='datetime64[ns]', freq=None)
pd.period_range("2020", periods=3, freq="M").to_timestamp(to_offset("ME"))
# Outputs DatetimeIndex(['2020-01-31', '2020-02-29', '2020-03-31'], dtype='datetime64[ns]', freq='ME') Wrong frequency
pd.period_range("2020", periods=2, freq="M").to_timestamp("ME") # Fails
pd.period_range("2020", periods=3, freq="M").to_timestamp("ME") # Fails
Issue Description
Related to #56213
Expected Behavior
All of these four lines should return a datetindex with 2ME
as frequency.
I suppose that the the frequency term in to_timestamp is ignored and the frequency is directly inferred.
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.10.13.final.0
python-bits : 64
OS : Darwin
OS-release : 23.2.0
Version : Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.1
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.1
Cython : 3.0.8
pytest : 7.4.0
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.12.2
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 2.0.28
tables : None
tabulate : None
xarray : 2024.1.1
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None