Skip to content

DatetimeIndex.to_period with freq #33358

Closed
@yohplala

Description

@yohplala
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas (1.0.3).

Code Sample

# Input date range:
pi5m = pd.date_range(start='2019-12-22 06:40:00+00:00', end='2019-12-22 08:45:00+00:00', freq='5min')

# Converting to PeriodIndex
pi5m.to_period()

  File "/home/p/.local/lib/python3.7/site-packages/pandas/core/arrays/period.py", line 938, in dt64arr_to_periodarr
    freq = Period._maybe_convert_freq(freq)

  File "pandas/_libs/tslibs/period.pyx", line 1580, in pandas._libs.tslibs.period._Period._maybe_convert_freq

AttributeError: 'NoneType' object has no attribute 'n'

# Working
pi5m.to_period('5min')

Problem description

It is specified in documentation that if not provided, freq is inferred.
However, with above-provided input, I get the error message indicated.
Is this a bug?

Thanks for your feedback.
Bests,

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypePeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions