Skip to content

ENH: Implement '_period_dtype_code' attribute to 'pandas._libs.tslibs.offsets.MonthBegin' #38859

Closed
@yohplala

Description

@yohplala

Code...

index_offsets = pd.tseries.frequencies.to_offset('1MS')
time_marker = pd.Timestamp('2020/01/02 1:59')
period = pd.Period(time_marker, freq = index_offsets.freqstr)

... raises following error message:

Traceback (most recent call last):

  File "pandas/_libs/tslibs/period.pyx", line 2436, in pandas._libs.tslibs.period.freq_to_dtype_code

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


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

Traceback (most recent call last):

  File "<ipython-input-63-c78e6c74b47c>", line 1, in <module>
    period = pd.Period(time_marker, freq = index_offsets.freqstr)

  File "pandas/_libs/tslibs/period.pyx", line 2422, in pandas._libs.tslibs.period.Period.__new__

  File "pandas/_libs/tslibs/period.pyx", line 2438, in pandas._libs.tslibs.period.freq_to_dtype_code

ValueError: Invalid frequency: {0}

Please, could an appropriate '_period_dtype_code' attribute be provided to 'pandas._libs.tslibs.offsets.MonthBegin' object to solve this error?
Thanks for your amazing lib!

INSTALLED VERSIONS
------------------
commit           : db08276bc116c438d3fdee492026f8223584c477
python           : 3.8.5.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.4.0-58-generic
Version          : #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : fr_FR.UTF-8
LOCALE           : fr_FR.UTF-8

pandas           : 1.1.3
numpy            : 1.19.2
pytz             : 2020.1
dateutil         : 2.8.1
pip              : 20.2.4
setuptools       : 50.3.1.post20201107
Cython           : 0.29.21
pytest           : 6.1.1
hypothesis       : None
sphinx           : 3.2.1
blosc            : None
feather          : None
xlsxwriter       : 1.3.7
lxml.etree       : 4.6.1
html5lib         : 1.1
pymysql          : None
psycopg2         : None
jinja2           : 2.11.2
IPython          : 7.19.0
pandas_datareader: None
bs4              : 4.9.3
bottleneck       : 1.3.2
fsspec           : 0.8.3
fastparquet      : 0.4.2
gcsfs            : None
matplotlib       : 3.3.2
numexpr          : 2.7.1
odfpy            : None
openpyxl         : 3.0.5
pandas_gbq       : None
pyarrow          : None
pytables         : None
pyxlsb           : None
s3fs             : None
scipy            : 1.5.2
sqlalchemy       : 1.3.20
tables           : 3.6.1
tabulate         : None
xarray           : None
xlrd             : 1.2.0
xlwt             : 1.3.0
numba            : 0.51.2

Not building from sources (using anaconda)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions