Skip to content

BUG: ufunc with PeriodIndex may raise IncompatibleFrequency #13980

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

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Aug 13, 2016

  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

PeriodIndex supportds addition / subtraction with integer.

# OK
pi = pd.PeriodIndex(['2011-01'], freq='M')
pi + 1
# PeriodIndex(['2011-02'], dtype='int64', freq='M')
pi - 1
# PeriodIndex(['2010-12'], dtype='int64', freq='M')

but raises if op is performed via ufunc.

# NG
np.add(pi, 1)
# pandas._period.IncompatibleFrequency: Input has different freq from PeriodIndex(freq=M)

np.subtract(pi, 1)
# pandas._period.IncompatibleFrequency: Input has different freq from PeriodIndex(freq=M)

@sinhrks sinhrks added Bug Period Period data type Compat pandas objects compatability with Numpy or Python functions labels Aug 13, 2016
@sinhrks sinhrks added this to the 0.19.0 milestone Aug 13, 2016
@codecov-io
Copy link

codecov-io commented Aug 13, 2016

Current coverage is 85.26% (diff: 54.54%)

No coverage report found for master at 1919e26.

Powered by Codecov. Last update 1919e26...f94d027

@@ -4075,8 +4075,10 @@ def test_pi_ops_nat(self):
'NaT', '2011-06'], freq='M', name='idx')
self._check(idx, lambda x: x + 2, expected)
self._check(idx, lambda x: 2 + x, expected)
self._check(idx, lambda x: np.add(x, 2), expected)
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 some tests for things that are not acceptable?

Copy link
Member Author

@sinhrks sinhrks Aug 17, 2016

Choose a reason for hiding this comment

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

Added a test case. Because current .values is internally int, it doesn't raise error as expected. As #13988 will change .values, let me revisit this at that time.

@sinhrks sinhrks force-pushed the period_numpy_ufunc branch 2 times, most recently from df5d585 to f51f7cd Compare August 16, 2016 11:10
@sinhrks sinhrks force-pushed the period_numpy_ufunc branch from f51f7cd to f94d027 Compare August 18, 2016 19:25
@jreback jreback closed this in a01e58f Aug 18, 2016
@jreback
Copy link
Contributor

jreback commented Aug 18, 2016

thanks!

can revisit #13988 with these changes.

@sinhrks sinhrks deleted the period_numpy_ufunc branch August 18, 2016 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants