-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
API DesignDatetimeDatetime data dtypeDatetime data dtypeIntervalInterval data typeInterval data typePeriodPeriod data typePeriod data typeTestingpandas testing functions or related to the test suitepandas testing functions or related to the test suite
Description
My impression (discussion somewhere on gitter) is that pd.Period
is supposed to be immutable. That would certainly make sense for objects going into a PeriodIndex
.
per = pd.Period('2014Q1')
>>> per
Period('2014Q1', 'Q-DEC')
freq = per.freq.copy()
freq.n *= 2
per.freq = freq
>>> per
Period('2014Q1', '2Q-DEC')
per.freq
is a DateOffset
object*, which is defined in tseries.offsets
. There is a comment in tseries.offsets.BusinessHourMixin.apply
saying "# calculate here because offset is not immutable".
So a couple of questions:
- Are we sure
pd.Period
should be immutable? If so, is there a preferred way of imposing that? Note that the class is defined in a .pyx file and some methods explicitly call__new__
. - Does the comment about offset not being immutable mean that it can't or shouldn't be? Outside of
__init__
and__setstate__
, the only place intseries.offsets
where I see anyself.foo
attributes being set isself.daytime = False
inBusinessHourMixin._get_business_hours_by_sec
. grepping for "daytime", this attribute does not appear to be referenced anywhere else.
* BTW, I think DateOffset
is one of a small number of commonly-used classes for which there is not a ABCDateOffset
equivalent. Is that by design? If not, I'll be happy to make one.
Metadata
Metadata
Assignees
Labels
API DesignDatetimeDatetime data dtypeDatetime data dtypeIntervalInterval data typeInterval data typePeriodPeriod data typePeriod data typeTestingpandas testing functions or related to the test suitepandas testing functions or related to the test suite