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

ENH: Period ops NaT & timedelta ops #5202

Closed
jreback opened this issue Oct 12, 2013 · 4 comments
Closed

ENH: Period ops NaT & timedelta ops #5202

jreback opened this issue Oct 12, 2013 · 4 comments
Labels
API Design Enhancement Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Period Period data type Timedelta Timedelta data type

Comments

@jreback
Copy link
Contributor

jreback commented Oct 12, 2013

see related #5200, #4551, #4056

seem that a direct subtraction of PeriodIndexes would accomplish this,
but don't seem to support those types of ops...

This is currently an intersection (with a '-'), but want to do a timedelta like op

In [40]: pd.PeriodIndex(start='20130101',end='20130501',freq='M').sub(
pd.PeriodIndex(start='20130201',end='20130401',freq='M'))

Partially supported actuallly

In [5]:  pd.PeriodIndex(start='20130101',end='20130501',freq='M').to_series()-pd.PeriodIndex(start='20130205',end='20130405',freq='M').to_series()
Out[5]: 
2013-01   NaN
2013-02     0
2013-03     0
2013-04     0
2013-05   NaN
Freq: M, dtype: float64

In [6]:  pd.PeriodIndex(start='20130101',end='20130201',freq='B').to_series()-pd.Period('20130101',freq='B')

TypeError: unsupported operand type(s) for -: 'int' and 'Period'
@jtratner
Copy link
Contributor

Dunno, think you should always have - be intersection, instead of adding ambiguity like that.

@jreback
Copy link
Contributor Author

jreback commented Oct 12, 2013

of course.....I am talking about adding a subtraction op to datetime like Index (we already support Index + offset),
should maybe have a .sub or something (or course can just do this in Series...which is prob better anyhow as I think we figured it all out)

@jreback jreback closed this as completed Jan 3, 2014
@jreback jreback reopened this Jan 3, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.0 Feb 18, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
jreback pushed a commit that referenced this issue May 6, 2016
Similar to #5202.

Author: sinhrks <[email protected]>

Closes #13071 from sinhrks/period_period_sub and squashes the following commits:

0f0951f [sinhrks] BUG: PeriodIndex and Period subtraction error
@jbrockmendel
Copy link
Member

One of the OP examples now works:

>>> pd.PeriodIndex(start='20130101',end='20130201',freq='B').to_series()-pd.Period('20130101',freq='B')
2013-01-01     0
2013-01-02     1
2013-01-03     2
2013-01-04     3
2013-01-07     4
2013-01-08     5
2013-01-09     6
2013-01-10     7
2013-01-11     8
2013-01-14     9
2013-01-15    10
2013-01-16    11
2013-01-17    12
2013-01-18    13
2013-01-21    14
2013-01-22    15
2013-01-23    16
2013-01-24    17
2013-01-25    18
2013-01-28    19
2013-01-29    20
2013-01-30    21
2013-01-31    22
2013-02-01    23
Freq: B, dtype: object

@jbrockmendel
Copy link
Member

@jreback closeable?

@jreback jreback closed this as completed Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Period Period data type Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

3 participants