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): result = this._fast_union(other, sort=sort) if sort is None: # In the case where sort is None, _can_fast_union # implies that result.freq should match self.freq assert result.freq == self.freq, (result.freq, self.freq) elif result.freq is None: # TODO: no tests rely on this; needed? result = result._with_freq("infer") return result else: i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self._union(i8other, sort=sort) result = type(self)(i8result, dtype=self.dtype, freq="infer") return result
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): result = this._fast_union(other, sort=sort) if sort is None: # In the case where sort is None, _can_fast_union # implies that result.freq should match self.freq assert result.freq == self.freq, (result.freq, self.freq) elif result.freq is None: # TODO: no tests rely on this; needed? result = result._with_freq("infer") return result else: i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self._union(i8other, sort=sort) # pandas\core\indexes\datetimelike.py:887: error: Unexpected # keyword argument "freq" for "DatetimeTimedeltaMixin" [call-arg] result = type(self)( i8result, dtype=self.dtype, freq="infer" # type: ignore[call-arg] ) return result
def _setop(self, other, sort, opname: str): """ Perform a set operation by dispatching to the Int64Index implementation. """ self._validate_sort_keyword(sort) self._assert_can_do_setop(other) res_name = get_op_result_name(self, other) other = ensure_index(other) i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = getattr(i8self, opname)(i8other, sort=sort) parr = type(self._data)(np.asarray(i8result, dtype=np.int64), dtype=self.dtype) result = type(self)._simple_new(parr, name=res_name) return result
def _union(self, other, sort): # We are called by `union`, which is responsible for this validation assert isinstance(other, type(self)) assert self.dtype == other.dtype if self._can_fast_union(other): result = self._fast_union(other, sort=sort) # in the case with sort=None, the _can_fast_union check ensures # that result.freq == self.freq return result else: i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self._union(i8other, sort=sort) result = type(self)(i8result, dtype=self.dtype, freq="infer") return result
def _shallow_copy(self, values=None, name: Label = no_default): name = self.name if name is no_default else name if values is None: return self._simple_new(self._range, name=name) else: return Int64Index._simple_new(values, name=name)
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: i8self = Int64Index._simple_new(self.asi8, name=self.name) i8other = Int64Index._simple_new(other.asi8, name=other.name) i8result = i8self._union(i8other, sort=sort) result = type(self)(i8result, dtype=self.dtype, freq="infer") return result
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)) if not is_dtype_equal(self.dtype, other.dtype): this = self.astype("O") other = other.astype("O") return this._union(other, sort=sort) i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self._union(i8other, sort=sort) res_name = get_op_result_name(self, other) result = self._shallow_copy(np.asarray(i8result, dtype=np.int64), name=res_name) return result
def _shallow_copy(self, values=None, name: Label = no_default): name = self.name if name is no_default else name if values is not None: if values.dtype.kind == "f": return Float64Index(values, name=name) return Int64Index._simple_new(values, name=name) result = self._simple_new(self._range, name=name) result._cache = self._cache return result
def intersection(self, other, sort=False): self._validate_sort_keyword(sort) self._assert_can_do_setop(other) res_name = get_op_result_name(self, other) other = ensure_index(other) if self.equals(other): return self._get_reconciled_name_object(other) if not is_dtype_equal(self.dtype, other.dtype): # TODO: fastpath for if we have a different PeriodDtype this = self.astype("O") other = other.astype("O") return this.intersection(other, sort=sort) i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self.intersection(i8other, sort=sort) result = self._shallow_copy(np.asarray(i8result, dtype=np.int64), name=res_name) return result
def difference(self, other, sort=None): self._validate_sort_keyword(sort) self._assert_can_do_setop(other) res_name = get_op_result_name(self, other) other = ensure_index(other) if self.equals(other): # pass an empty PeriodArray with the appropriate dtype return self._shallow_copy(self._data[:0]) if is_object_dtype(other): return self.astype(object).difference(other).astype(self.dtype) elif not is_dtype_equal(self.dtype, other.dtype): return self i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self.difference(i8other, sort=sort) result = self._shallow_copy(np.asarray(i8result, dtype=np.int64), name=res_name) return result
def _shallow_copy(self, values, name: Hashable = no_default): name = self.name if name is no_default else name if values.dtype.kind == "f": return Float64Index(values, name=name) # GH 46675 & 43885: If values is equally spaced, return a # more memory-compact RangeIndex instead of Int64Index unique_diffs = unique_deltas(values) if len(unique_diffs) == 1 and unique_diffs[0] != 0: diff = unique_diffs[0] new_range = range(values[0], values[-1] + diff, diff) return type(self)._simple_new(new_range, name=name) else: return Int64Index._simple_new(values, name=name)
def _int64index(self) -> Int64Index: return Int64Index._simple_new(self.asi8, name=self.name)
def _int64index(self): return Int64Index._simple_new(self._data, name=self.name)
def _shallow_copy(self, values, name: Hashable = no_default): name = self.name if name is no_default else name if values.dtype.kind == "f": return Float64Index(values, name=name) return Int64Index._simple_new(values, name=name)
def _cached_int64index(self) -> Int64Index: return Int64Index._simple_new(self._data, name=self.name)