Use ._tshift internally for datetimelike ops · pandas-dev/pandas@23e5cfc (original) (raw)

`@@ -455,7 +455,7 @@ def _sub_period_array(self, other):

`

455

455

`def _addsub_int_array(self, other, op):

`

456

456

`"""

`

457

457

` Add or subtract array-like of integers equivalent to applying

`

458

``

`` -

shift pointwise.

``

``

458

`` +

_tshift pointwise.

``

459

459

``

460

460

` Parameters

`

461

461

` ----------

`

`@@ -553,6 +553,23 @@ def shift(self, periods, freq=None):

`

553

553

` --------

`

554

554

` Index.shift : Shift values of Index.

`

555

555

` """

`

``

556

`+

return self._tshift(periods=periods, freq=freq)

`

``

557

+

``

558

`+

def _tshift(self, periods, freq=None):

`

``

559

`+

"""

`

``

560

`` +

Shift each value by periods.

``

``

561

+

``

562

`+

Note this is different from ExtensionArray.shift, which

`

``

563

`+

shifts the position of each element, padding the end with

`

``

564

`+

missing values.

`

``

565

+

``

566

`+

Parameters

`

``

567

`+


`

``

568

`+

periods : int

`

``

569

`+

Number of periods to shift by.

`

``

570

`+

freq : pandas.DateOffset, pandas.Timedelta, or string

`

``

571

`+

Frequency increment to shift by.

`

``

572

`+

"""

`

556

573

`if freq is not None and freq != self.freq:

`

557

574

`if isinstance(freq, compat.string_types):

`

558

575

`freq = frequencies.to_offset(freq)

`

`@@ -600,7 +617,7 @@ def add(self, other):

`

600

617

`elif lib.is_integer(other):

`

601

618

`# This check must come after the check for np.timedelta64

`

602

619

`# as is_integer returns True for these

`

603

``

`-

result = self.shift(other)

`

``

620

`+

result = self._tshift(other)

`

604

621

``

605

622

`# array-like others

`

606

623

`elif is_timedelta64_dtype(other):

`

`@@ -652,7 +669,7 @@ def sub(self, other):

`

652

669

`elif lib.is_integer(other):

`

653

670

`# This check must come after the check for np.timedelta64

`

654

671

`# as is_integer returns True for these

`

655

``

`-

result = self.shift(-other)

`

``

672

`+

result = self._tshift(-other)

`

656

673

`elif isinstance(other, Period):

`

657

674

`result = self._sub_period(other)

`

658

675

``