Skip to content

BUG: QuarterBegin Does not work with Period #55785

Closed
@cancan101

Description

@cancan101

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

import pandas as pd
pd.Period(year=2014, quarter=3, freq=pd.offsets.QuarterBegin(startingMonth=12))

Issue Description

Unable to to create a Quarterly period as defined by the start of the quarter vs the end.

Might be related to this very old issue: #5091

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File period.pyx:2839, in pandas._libs.tslibs.period.freq_to_dtype_code()

AttributeError: 'pandas._libs.tslibs.offsets.QuarterBegin' object has no attribute '_period_dtype_code'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
File period.pyx:2841, in pandas._libs.tslibs.period.freq_to_dtype_code()

ValueError: Invalid frequency: <QuarterBegin: startingMonth=12>
Exception ignored in: 'pandas._libs.tslibs.period._ordinal_from_fields'
Traceback (most recent call last):
  File "period.pyx", line 2841, in pandas._libs.tslibs.period.freq_to_dtype_code
ValueError: Invalid frequency: <QuarterBegin: startingMonth=12>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[14], line 1
----> 1 pd.Period(year=2014, quarter=3, freq=pd.offsets.QuarterBegin(startingMonth=12))

File period.pyx:2830, in pandas._libs.tslibs.period.Period.__new__()

File period.pyx:1779, in pandas._libs.tslibs.period._Period._from_ordinal()

File period.pyx:1742, in pandas._libs.tslibs.period._Period.__cinit__()

AttributeError: 'pandas._libs.tslibs.offsets.QuarterBegin' object has no attribute '_period_dtype_code'

Expected Behavior

Period('2014Q3', 'QS-DEC')

Installed Versions

INSTALLED VERSIONS

commit : a60ad39
python : 3.12.0.final.0
python-bits : 64
OS : Darwin
OS-release : 22.1.0
Version : Darwin Kernel Version 22.1.0: Sun Oct 9 20:19:12 PDT 2022; root:xnu-8792.41.9~3/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.1.2
numpy : 1.26.1
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.17.2
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions