Example #1
0
    def _get_indexer(self, target, method=None, limit=None, tolerance=None):
        if com.any_not_none(method, tolerance,
                            limit) or not is_list_like(target):
            return super()._get_indexer(target,
                                        method=method,
                                        tolerance=tolerance,
                                        limit=limit)

        if self.step > 0:
            start, stop, step = self.start, self.stop, self.step
        else:
            # GH 28678: work on reversed range for simplicity
            reverse = self._range[::-1]
            start, stop, step = reverse.start, reverse.stop, reverse.step

        target_array = np.asarray(target)
        if not (is_signed_integer_dtype(target_array)
                and target_array.ndim == 1):
            # checks/conversions/roundings are delegated to general method
            return super()._get_indexer(target,
                                        method=method,
                                        tolerance=tolerance)

        locs = target_array - start
        valid = (locs % step == 0) & (locs >= 0) & (target_array < stop)
        locs[~valid] = -1
        locs[valid] = locs[valid] / step

        if step != self.step:
            # We reversed this range: transform to original locs
            locs[valid] = len(self) - 1 - locs[valid]
        return ensure_platform_int(locs)
Example #2
0
 def _validate_fill_value(self, value):
     # e.g. np.array([1]) we want np.array([1], dtype=np.uint64)
     #  see test_where_uin64
     super()._validate_fill_value(value)
     if hasattr(value, "dtype") and is_signed_integer_dtype(value.dtype):
         if (value >= 0).all():
             return value.astype(self.dtype)
         raise TypeError
     return value
Example #3
0
def test_is_signed_integer_dtype():
    assert not com.is_signed_integer_dtype(str)
    assert not com.is_signed_integer_dtype(float)
    assert not com.is_signed_integer_dtype(np.uint64)
    assert not com.is_signed_integer_dtype(np.datetime64)
    assert not com.is_signed_integer_dtype(np.timedelta64)
    assert not com.is_signed_integer_dtype(pd.Index([1, 2.]))
    assert not com.is_signed_integer_dtype(np.array(['a', 'b']))
    assert not com.is_signed_integer_dtype(np.array([1, 2], dtype=np.uint32))
    assert not com.is_signed_integer_dtype(np.array([], dtype=np.timedelta64))

    assert com.is_signed_integer_dtype(int)
    assert com.is_signed_integer_dtype(pd.Series([1, 2]))
Example #4
0
def test_is_not_signed_integer_dtype(dtype):
    assert not com.is_signed_integer_dtype(dtype)
Example #5
0
def test_is_signed_integer_dtype():
    assert not com.is_signed_integer_dtype(str)
    assert not com.is_signed_integer_dtype(float)
    assert not com.is_signed_integer_dtype(np.uint64)
    assert not com.is_signed_integer_dtype(np.datetime64)
    assert not com.is_signed_integer_dtype(np.timedelta64)
    assert not com.is_signed_integer_dtype(pd.Index([1, 2.]))
    assert not com.is_signed_integer_dtype(np.array(['a', 'b']))
    assert not com.is_signed_integer_dtype(np.array([1, 2], dtype=np.uint32))
    assert not com.is_signed_integer_dtype(np.array([], dtype=np.timedelta64))

    assert com.is_signed_integer_dtype(int)
    assert com.is_signed_integer_dtype(pd.Series([1, 2]))
Example #6
0
def test_is_not_signed_integer_dtype(dtype):
    assert not com.is_signed_integer_dtype(dtype)