Skip to content

Period/DatetimeIndex may not be broadcasting correctly #5032

Closed
@jtratner

Description

@jtratner

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]')

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsNumeric OperationsArithmetic, Comparison, and Logical operationsPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions