Skip to content

BUG: Period ops with np.timedelta64 cause unexpected result #7740

Closed
@sinhrks

Description

@sinhrks

Period + np.timedelta64 doesn't raise TypeError(NotImplemented) (like offsets does), and results in erratic internal representation.

import pandas as pd
import numpy as np

p = pd.Period('2011-01-01', freq='D')
p = p + np.timedelta64(2, 'h')
# This raises no error

print(p)
# TypeError: don't know how to convert scalar number to int

p.ordinal
#14977 hours

PeriodIndex + np.timedelta64 also doesn't raise TypeError(NotImplemented), and are added ignoring PeriodIndex.freq.

pidx = pd.period_range('2011-01-01', freq='D', periods=5)
pidx = pidx + np.timedelta64(2, 'h')
pidx
# <class 'pandas.tseries.period.PeriodIndex'>
# [2011-01-03, ..., 2011-01-07]
# Length: 5, Freq: D

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions