示例#1
0
 def _broadcast(arr_or_scalar, shape):
     """
     Helper function to broadcast arrays / scalars to the desired shape.
     """
     if _np_version_under1p10:
         if lib.isscalar(arr_or_scalar):
             out = np.empty(shape)
             out.fill(arr_or_scalar)
         else:
             out = arr_or_scalar
     else:
         out = np.broadcast_to(arr_or_scalar, shape)
     return out
示例#2
0
def _ensure_datetimelike_to_i8(other):
    """ helper for coercing an input scalar or array to i8 """
    if lib.isscalar(other) and isna(other):
        other = iNaT
    elif isinstance(other, ABCIndexClass):
        # convert tz if needed
        if getattr(other, 'tz', None) is not None:
            other = other.tz_localize(None).asi8
        else:
            other = other.asi8
    else:
        try:
            other = np.array(other, copy=False).view('i8')
        except TypeError:
            # period array cannot be coerces to int
            other = Index(other).asi8
    return other
示例#3
0
def _ensure_datetimelike_to_i8(other):
    """ helper for coercing an input scalar or array to i8 """
    if lib.isscalar(other) and isna(other):
        other = iNaT
    elif isinstance(other, ABCIndexClass):
        # convert tz if needed
        if getattr(other, 'tz', None) is not None:
            other = other.tz_localize(None).asi8
        else:
            other = other.asi8
    else:
        try:
            other = np.array(other, copy=False).view('i8')
        except TypeError:
            # period array cannot be coerces to int
            other = Index(other).asi8
    return other