Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sinhrks opened this issue Jul 12, 2014 · 1 comment · Fixed by #7966
Closed

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

sinhrks opened this issue Jul 12, 2014 · 1 comment · Fixed by #7966
Labels
Bug Period Period data type Timedelta Timedelta data type
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jul 12, 2014

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
@sinhrks
Copy link
Member Author

sinhrks commented Jul 13, 2014

Related to #5202.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Period Period data type Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants