Skip to content

Period/DatetimeIndex may not be broadcasting correctly #5032

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
jtratner opened this issue Sep 29, 2013 · 2 comments
Closed

Period/DatetimeIndex may not be broadcasting correctly #5032

jtratner opened this issue Sep 29, 2013 · 2 comments
Labels
Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type

Comments

@jtratner
Copy link
Contributor

First two examples pass, third example doesn't.

# GH 4629
# arithmetic datetime64 ops with an index
s = Series(date_range('20130101',periods=5),index=date_range('20130101',periods=5))
expected = s-s.index.to_series()
result = s-s.index
assert_series_equal(result,expected)

result = s-s.index.to_period()
assert_series_equal(result,expected)

result2 = s.index.to_period() - s
expected2 = s.index.to_series() - s
assert_series_equal(result2, expected2)

Traceback:

  /usr/local/bin/vim +2583 pandas/tests/test_series.py  # test_datetime64_with_index
    result2 = s.index.to_period() - s
  /usr/local/bin/vim +873  pandas/tseries/period.py  # __sub__
    return PeriodIndex(ordinal=self.values - other, freq=self.freq)
TypeError: ufunc subtract cannot use operands with types dtype('int64') and dtype('<M8[ns]')
@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 Apr 9, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@max-sixty
Copy link
Contributor

@jreback this now works fine for me:

In [47]: expected = s-s.index.to_series()

In [48]: result = s-s.index

In [49]: assert_series_equal(result,expected)

In [50]: result2 = s.index.to_period() - s

In [51]: expected2 = s.index.to_series() - s

In [52]: assert_series_equal(result2, expected2)

In [53]: expected = s-s.index.to_series()

In [54]: result = s-s.index

In [55]: assert_series_equal(result,expected)

In [56]: 

In [56]: result = s-s.index.to_period()

In [57]: assert_series_equal(result,expected)

In [58]: 

In [58]: result2 = s.index.to_period() - s

In [59]: expected2 = s.index.to_series() - s

In [60]: assert_series_equal(result2, expected2)

In [61]: 

@jreback
Copy link
Contributor

jreback commented Sep 7, 2015

hmm must have been a duplicate issue
closed by #10638

@jreback jreback closed this as completed Sep 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Numeric Operations Arithmetic, Comparison, and Logical operations Period Period data type
Projects
None yet
Development

No branches or pull requests

3 participants