Beispiel #1
0
    def __new__(cls, data, closed=None, dtype=None, copy=False,
                name=None, verify_integrity=True):

        if name is None and hasattr(data, 'name'):
            name = data.name

        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(data, closed=closed, copy=copy, dtype=dtype,
                                  verify_integrity=verify_integrity)

        return cls._simple_new(array, name)
Beispiel #2
0
    def from_intervals(cls, data, closed=None, name=None, copy=False,
                       dtype=None):
        msg = ('IntervalIndex.from_intervals is deprecated and will be '
               'removed in a future version; Use IntervalIndex(...) instead')
        warnings.warn(msg, FutureWarning, stacklevel=2)
        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(data, closed=closed, copy=copy, dtype=dtype)

        if name is None and isinstance(data, cls):
            name = data.name

        return cls._simple_new(array, name=name)
Beispiel #3
0
 def take(self,
          indices,
          axis=0,
          allow_fill=True,
          fill_value=None,
          **kwargs):
     with rewrite_exception("Int64Index", type(self).__name__):
         return self._int64index.take(
             indices,
             axis=axis,
             allow_fill=allow_fill,
             fill_value=fill_value,
             **kwargs,
         )
Beispiel #4
0
 def from_tuples(
     cls,
     data,
     closed: str = "right",
     name=None,
     copy: bool = False,
     dtype: Optional[Dtype] = None,
 ):
     with rewrite_exception("IntervalArray", cls.__name__):
         arr = IntervalArray.from_tuples(data,
                                         closed=closed,
                                         copy=copy,
                                         dtype=dtype)
     return cls._simple_new(arr, name=name)
Beispiel #5
0
 def from_arrays(
     cls,
     left,
     right,
     closed: str = "right",
     name=None,
     copy: bool = False,
     dtype=None,
 ):
     with rewrite_exception("IntervalArray", cls.__name__):
         array = IntervalArray.from_arrays(
             left, right, closed, copy=copy, dtype=dtype
         )
     return cls._simple_new(array, name=name)
Beispiel #6
0
 def from_breaks(
     cls,
     breaks,
     closed: str = "right",
     name: Hashable = None,
     copy: bool = False,
     dtype: Dtype | None = None,
 ) -> IntervalIndex:
     with rewrite_exception("IntervalArray", cls.__name__):
         array = IntervalArray.from_breaks(breaks,
                                           closed=closed,
                                           copy=copy,
                                           dtype=dtype)
     return cls._simple_new(array, name=name)
Beispiel #7
0
    def __new__(cls, data, closed=None, dtype=None, copy=False,
                name=None, fastpath=False, verify_integrity=True):

        if fastpath:
            return cls._simple_new(data, name)

        if name is None and hasattr(data, 'name'):
            name = data.name

        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(data, closed=closed, copy=copy, dtype=dtype,
                                  fastpath=fastpath,
                                  verify_integrity=verify_integrity)

        return cls._simple_new(array, name)
Beispiel #8
0
 def from_arrays(
     cls,
     left,
     right,
     closed: IntervalClosedType = "right",
     name: Hashable = None,
     copy: bool = False,
     dtype: Dtype | None = None,
 ) -> IntervalIndex:
     with rewrite_exception("IntervalArray", cls.__name__):
         array = IntervalArray.from_arrays(left,
                                           right,
                                           closed,
                                           copy=copy,
                                           dtype=dtype)
     return cls._simple_new(array, name=name)
Beispiel #9
0
    def from_intervals(cls,
                       data,
                       closed=None,
                       name=None,
                       copy=False,
                       dtype=None):
        msg = ('IntervalIndex.from_intervals is deprecated and will be '
               'removed in a future version; Use IntervalIndex(...) instead')
        warnings.warn(msg, FutureWarning, stacklevel=2)
        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(data, closed=closed, copy=copy, dtype=dtype)

        if name is None and isinstance(data, cls):
            name = data.name

        return cls._simple_new(array, name=name)
Beispiel #10
0
    def from_tuples(
        cls,
        data,
        inclusive: IntervalInclusiveType | None = None,
        name: Hashable = None,
        copy: bool = False,
        dtype: Dtype | None = None,
    ) -> IntervalIndex:

        if inclusive is None:
            inclusive = "right"

        with rewrite_exception("IntervalArray", cls.__name__):
            arr = IntervalArray.from_tuples(data,
                                            inclusive=inclusive,
                                            copy=copy,
                                            dtype=dtype)
        return cls._simple_new(arr, name=name)
Beispiel #11
0
    def from_tuples(
        cls,
        data,
        inclusive=None,
        closed: None | lib.NoDefault = lib.no_default,
        name: Hashable = None,
        copy: bool = False,
        dtype: Dtype | None = None,
    ) -> IntervalIndex:

        inclusive, closed = _warning_interval(inclusive, closed)
        if inclusive is None:
            inclusive = "both"

        with rewrite_exception("IntervalArray", cls.__name__):
            arr = IntervalArray.from_tuples(
                data, inclusive=inclusive, copy=copy, dtype=dtype
            )
        return cls._simple_new(arr, name=name)
Beispiel #12
0
    def __new__(
        cls,
        data,
        closed=None,
        dtype=None,
        copy: bool = False,
        name=None,
        verify_integrity: bool = True,
    ):

        name = maybe_extract_name(name, data, cls)

        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(
                data,
                closed=closed,
                copy=copy,
                dtype=dtype,
                verify_integrity=verify_integrity,
            )

        return cls._simple_new(array, name)
Beispiel #13
0
    def astype(self, dtype, copy: bool = True) -> Index:
        dtype = pandas_dtype(dtype)
        if is_dtype_equal(self.dtype, dtype):
            if not copy:
                # Ensure that self.astype(self.dtype) is self
                return self
            return self.copy()

        if (isinstance(self.dtype, np.dtype) and isinstance(dtype, np.dtype)
                and dtype.kind == "M" and dtype != "M8[ns]"):
            # For now Datetime supports this by unwrapping ndarray, but DTI doesn't
            raise TypeError(f"Cannot cast {type(self).__name__} to dtype")

        with rewrite_exception(type(self._data).__name__, type(self).__name__):
            new_values = self._data.astype(dtype, copy=copy)

        # pass copy=False because any copying will be done in the
        #  _data.astype call above
        return Index(new_values,
                     dtype=new_values.dtype,
                     name=self.name,
                     copy=False)
Beispiel #14
0
    def __new__(
        cls,
        data,
        inclusive: IntervalInclusiveType | None = None,
        dtype: Dtype | None = None,
        copy: bool = False,
        name: Hashable = None,
        verify_integrity: bool = True,
    ) -> IntervalIndex:

        name = maybe_extract_name(name, data, cls)

        with rewrite_exception("IntervalArray", cls.__name__):
            array = IntervalArray(
                data,
                inclusive=inclusive,
                copy=copy,
                dtype=dtype,
                verify_integrity=verify_integrity,
            )

        return cls._simple_new(array, name)
Beispiel #15
0
 def astype(self, dtype, copy=True):
     with rewrite_exception('IntervalArray', self.__class__.__name__):
         new_values = self.values.astype(dtype, copy=copy)
     if is_interval_dtype(new_values):
         return self._shallow_copy(new_values.left, new_values.right)
     return super(IntervalIndex, self).astype(dtype, copy=copy)
Beispiel #16
0
 def from_arrays(cls, left, right, closed='right', name=None, copy=False,
                 dtype=None):
     with rewrite_exception("IntervalArray", cls.__name__):
         array = IntervalArray.from_arrays(left, right, closed, copy=copy,
                                           dtype=dtype)
     return cls._simple_new(array, name=name)
Beispiel #17
0
 def astype(self, dtype, copy: bool = True):
     with rewrite_exception("IntervalArray", type(self).__name__):
         new_values = self._values.astype(dtype, copy=copy)
     return Index(new_values, dtype=new_values.dtype, name=self.name)
Beispiel #18
0
 def from_tuples(cls, data, closed='right', name=None, copy=False,
                 dtype=None):
     with rewrite_exception("IntervalArray", cls.__name__):
         arr = IntervalArray.from_tuples(data, closed=closed, copy=copy,
                                         dtype=dtype)
     return cls._simple_new(arr, name=name)
Beispiel #19
0
 def astype(self, dtype, copy=True):
     with rewrite_exception('IntervalArray', self.__class__.__name__):
         new_values = self.values.astype(dtype, copy=copy)
     if is_interval_dtype(new_values):
         return self._shallow_copy(new_values.left, new_values.right)
     return super().astype(dtype, copy=copy)
Beispiel #20
0
 def astype(self, dtype, copy=True):
     with rewrite_exception("IntervalArray", type(self).__name__):
         new_values = self._values.astype(dtype, copy=copy)
     if is_interval_dtype(new_values.dtype):
         return self._shallow_copy(new_values)
     return Index.astype(self, dtype, copy=copy)
Beispiel #21
0
 def from_breaks(cls, breaks, closed="right", name=None, copy=False, dtype=None):
     with rewrite_exception("IntervalArray", cls.__name__):
         array = IntervalArray.from_breaks(
             breaks, closed=closed, copy=copy, dtype=dtype
         )
     return cls._simple_new(array, name=name)