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/BUG: DatetimeIndex and PeriodIndex in-place ops behaves incorrectly #7741

Merged
merged 1 commit into from
Jul 23, 2014

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jul 13, 2014

Fixes 2 issues related to DetetimeIndex and PeriodIndex ops.

pidx + pidx
# TypeError: unsupported operand type(s) for +: 'PeriodIndex' and 'PeriodIndex'
didx = pd.date_range('2011-01-01', freq='D', periods=5)

# This results shift (expected)
didx + 1
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-02, ..., 2011-01-06]
# Length: 5, Freq: D, Timezone: None

# This result adding 1 unit (nano second) (NG)
didx += 1
didx 
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2011-01-01 00:00:00.000000001, ..., 2011-01-05 00:00:00.000000001]
# Length: 5, Freq: None, Timezone: None

@sinhrks sinhrks changed the title ENH: PeriodIndex ops can accept Index ENH/BUG: DatetimeIndex and PeriodIndex in-place ops behaves incorrectly Jul 13, 2014
@jreback jreback modified the milestones: 0.15.1, 0.15.0 Jul 14, 2014
@sinhrks
Copy link
Member Author

sinhrks commented Jul 19, 2014

This can solve #3367. Test cases are added.

@@ -729,6 +825,86 @@ def test_representation(self):
result = getattr(idx, func)()
self.assertEqual(result, expected)

def test_add_iadd(self):
# union
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a couple of tests that have Periods with another freq as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, added few more test both for addition and subtraction. There seems to be a problem for non-monotonic PeriodIndex.union and diff. I'll dig in...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant like adding 'M' (higher than day freq). lmk

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Added tests for 'M' and 'A'.

@jreback
Copy link
Contributor

jreback commented Jul 23, 2014

look good..thanks

jreback added a commit that referenced this pull request Jul 23, 2014
ENH/BUG: DatetimeIndex and PeriodIndex in-place ops behaves incorrectly
@jreback jreback merged commit 492605e into pandas-dev:master Jul 23, 2014
@sinhrks sinhrks deleted the period_ops branch July 25, 2014 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Period Period data type
Projects
None yet
2 participants