def str_repeat(arr, repeats): """ Duplicate each string in the array by indicated number of times Parameters ---------- repeats : int or array Same value for all (int) or different value per (array) Returns ------- repeated : array """ if np.isscalar(repeats): def rep(x): try: return compat.binary_type.__mul__(x, repeats) except TypeError: return compat.text_type.__mul__(x, repeats) return _na_map(rep, arr) else: def rep(x, r): try: return compat.binary_type.__mul__(x, r) except TypeError: return compat.text_type.__mul__(x, r) repeats = np.asarray(repeats, dtype=object) result = lib.vec_binop(_values_from_object(arr), repeats, rep) return result
def na_op(x, y): try: result = op(x, y) except TypeError: if isinstance(y, list): y = lib.list_to_object_array(y) if isinstance(y, (np.ndarray, pd.Series)): if (is_bool_dtype(x.dtype) and is_bool_dtype(y.dtype)): result = op(x, y) # when would this be hit? else: x = com._ensure_object(x) y = com._ensure_object(y) result = lib.vec_binop(x, y, op) else: try: # let null fall thru if not isnull(y): y = bool(y) result = lib.scalar_binop(x, y, op) except: raise TypeError("cannot compare a dtyped [{0}] array with " "a scalar of type [{1}]".format( x.dtype, type(y).__name__)) return result
def str_repeat(arr, repeats): """ Duplicate each string in the array by indicated number of times Parameters ---------- repeats : int or array Same value for all (int) or different value per (array) Returns ------- repeated : array """ if np.isscalar(repeats): def rep(x): try: return str.__mul__(x, repeats) except TypeError: return str.__mul__(x, repeats) return _na_map(rep, arr) else: def rep(x, r): try: return str.__mul__(x, r) except TypeError: return str.__mul__(x, r) repeats = np.asarray(repeats, dtype=object) result = lib.vec_binop(arr, repeats, rep) return result
def na_op(x, y): try: result = op(x, y) except TypeError: if isinstance(y, list): y = lib.list_to_object_array(y) if isinstance(y, (np.ndarray, pd.Series)): if (x.dtype == np.bool_ and y.dtype == np.bool_): # pragma: no cover result = op(x, y) # when would this be hit? else: x = com._ensure_object(x) y = com._ensure_object(y) result = lib.vec_binop(x, y, op) else: try: # let null fall thru if not isnull(y): y = bool(y) result = lib.scalar_binop(x, y, op) except: raise TypeError("cannot compare a dtyped [{0}] array with " "a scalar of type [{1}]".format( x.dtype, type(y).__name__)) return result
def str_repeat(arr, repeats): """ Duplicate each string in the Series/Index by indicated number of times. Parameters ---------- repeats : int or array Same value for all (int) or different value per (array) Returns ------- repeated : Series/Index of objects """ if np.isscalar(repeats): def rep(x): try: return compat.binary_type.__mul__(x, repeats) except TypeError: return compat.text_type.__mul__(x, repeats) return _na_map(rep, arr) else: def rep(x, r): try: return compat.binary_type.__mul__(x, r) except TypeError: return compat.text_type.__mul__(x, r) repeats = np.asarray(repeats, dtype=object) result = lib.vec_binop(_values_from_object(arr), repeats, rep) return result