Exemplo n.º 1
0
    def _union(self, other, sort):
        if not len(other) or self.equals(other) or not len(self):
            return super()._union(other, sort=sort)

        if len(other) == 0 or self.equals(other) or len(self) == 0:
            return super().union(other, sort=sort)

        if not isinstance(other, DatetimeIndex):
            try:
                other = DatetimeIndex(other)
            except TypeError:
                pass

        this, other = self._maybe_utc_convert(other)

        if this._can_fast_union(other):
            return this._fast_union(other, sort=sort)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, DatetimeIndex):
                # TODO: we shouldn't be setting attributes like this;
                #  in all the tests this equality already holds
                result._data._dtype = this.dtype
                if result.freq is None and (this.freq is not None
                                            or other.freq is not None):
                    result._set_freq("infer")
            return result
Exemplo n.º 2
0
    def _union(self, other: "TimedeltaIndex", sort):
        if len(other) == 0 or self.equals(other) or len(self) == 0:
            return super()._union(other, sort=sort)

        # We are called by `union`, which is responsible for this validation
        assert isinstance(other, TimedeltaIndex)

        this, other = self, other

        if this._can_fast_union(other):
            return this._fast_union(other, sort=sort)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, TimedeltaIndex):
                if result.freq is None:
                    result._set_freq("infer")
            return result
Exemplo n.º 3
0
    def _union(self, other, sort):
        if not len(other) or self.equals(other) or not len(self):
            return super()._union(other, sort=sort)

        # We are called by `union`, which is responsible for this validation
        assert isinstance(other, type(self))

        this, other = self._maybe_utc_convert(other)

        if this._can_fast_union(other):
            return this._fast_union(other, sort=sort)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, type(self)):
                assert result._data.dtype == this.dtype
                if result.freq is None:
                    result._set_freq("infer")
            return result
Exemplo n.º 4
0
    def _union(self, other, sort):
        if len(other) == 0 or self.equals(other) or len(self) == 0:
            return super()._union(other, sort=sort)

        if not isinstance(other, TimedeltaIndex):
            try:
                other = TimedeltaIndex(other)
            except (TypeError, ValueError):
                pass
        this, other = self, other

        if this._can_fast_union(other):
            return this._fast_union(other)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, TimedeltaIndex):
                if result.freq is None:
                    result._set_freq("infer")
            return result
Exemplo n.º 5
0
    def _union(self, other, sort):
        if len(other) == 0 or self.equals(other) or len(self) == 0:
            return super()._union(other, sort=sort)

        if not isinstance(other, TimedeltaIndex):
            try:
                other = TimedeltaIndex(other)
            except (TypeError, ValueError):
                pass
        this, other = self, other

        if this._can_fast_union(other):
            return this._fast_union(other)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, TimedeltaIndex):
                if result.freq is None:
                    result.freq = to_offset(result.inferred_freq)
            return result
Exemplo n.º 6
0
    def _union(self, other, sort):
        if len(other) == 0 or self.equals(other) or len(self) == 0:
            return super()._union(other, sort=sort)

        if not isinstance(other, TimedeltaIndex):
            try:
                other = TimedeltaIndex(other)
            except (TypeError, ValueError):
                pass
        this, other = self, other

        if this._can_fast_union(other):
            return this._fast_union(other)
        else:
            result = Index._union(this, other, sort=sort)
            if isinstance(result, TimedeltaIndex):
                if result.freq is None:
                    # TODO: find a less code-smelly way to set this
                    result._data._freq = to_offset(result.inferred_freq)
            return result