def __getitem__(self, val):
     """Returns a TimeSeriesRDD representing a subslice of this TimeSeriesRDD, containing only
     values for a sub-range of the time it covers.
     """
     start = datetime_to_millis(val.start)
     stop = datetime_to_millis(val.stop)
     return TimeSeriesRDD(None, None, self._jtsrdd.slice(start, stop), self.ctx)
Example #2
0
def uniform(start, end=None, periods=None, freq=None, sc=None):
    """
    Instantiates a uniform DateTimeIndex.

    Either end or periods must be specified.
    
    Parameters
    ----------
        start : string, long (millis from epoch), or Pandas Timestamp
        end : string, long (millis from epoch), or Pandas Timestamp
        periods : int
        freq : a frequency object
        sc : SparkContext
    """
    dtmodule = sc._jvm.com.cloudera.sparkts.__getattr__(
        'DateTimeIndex$').__getattr__('MODULE$')
    if freq is None:
        raise ValueError("Missing frequency")
    elif end is None and periods == None:
        raise ValueError("Need an end date or number of periods")
    elif end is not None:
        return DateTimeIndex(dtmodule.uniform( \
            datetime_to_millis(start), datetime_to_millis(end), freq._jfreq))
    else:
        return DateTimeIndex(dtmodule.uniform( \
            datetime_to_millis(start), periods, freq._jfreq))
def uniform(start, end=None, periods=None, freq=None, sc=None):
    """
    Instantiates a uniform DateTimeIndex.

    Either end or periods must be specified.
    
    Parameters
    ----------
        start : string, long (millis from epoch), or Pandas Timestamp
        end : string, long (millis from epoch), or Pandas Timestamp
        periods : int
        freq : a frequency object
        sc : SparkContext
    """
    dtmodule = sc._jvm.com.cloudera.sparkts.__getattr__('DateTimeIndex$').__getattr__('MODULE$')
    if freq is None:
        raise ValueError("Missing frequency")
    elif end is None and periods == None:
        raise ValueError("Need an end date or number of periods")
    elif end is not None:
        return DateTimeIndex(dtmodule.uniform( \
            datetime_to_millis(start), datetime_to_millis(end), freq._jfreq))
    else:
        return DateTimeIndex(dtmodule.uniform( \
            datetime_to_millis(start), periods, freq._jfreq))
Example #4
0
 def __getitem__(self, val):
     # TODO: throw an error if the step size is defined
     if isinstance(val, slice):
         start = datetime_to_millis(val.start)
         stop = datetime_to_millis(val.stop)
         jdt_index = self._jdt_index.slice(start, stop)
         return DateTimeIndex(jdt_index)
     else:
         return self._jdt_index.locAtDateTime(datetime_to_millis(val))
Example #5
0
 def __getitem__(self, val):
     """
     Returns a TimeSeriesRDD representing a subslice of this TimeSeriesRDD, containing only
     values for a sub-range of the time it covers.
     """
     start = datetime_to_millis(val.start)
     stop = datetime_to_millis(val.stop)
     return TimeSeriesRDD(None, None, self._jtsrdd.slice(start, stop),
                          self.ctx)
Example #6
0
 def __getitem__(self, val):
     # TODO: throw an error if the step size is defined
     if isinstance(val, slice):
         start = datetime_to_millis(val.start)
         stop = datetime_to_millis(val.stop)
         jdt_index = self._jdt_index.slice(start, stop)
         return DateTimeIndex(jdt_index)
     else:
         return self._jdt_index.locAtDateTime(datetime_to_millis(val))
def irregular(timestamps, sc):
    """
    Instantiates an irregular DateTimeIndex.
    
    Parameters
    ----------
        timestamps : a Pandas DateTimeIndex, or an array of strings, longs (nanos from epoch), Pandas
            Timestamps
        sc : SparkContext
    """
    dtmodule = sc._jvm.com.cloudera.sparkts.__getattr__('DateTimeIndex$').__getattr__('MODULE$')
    arr = sc._gateway.new_array(sc._jvm.long, len(timestamps))
    for i in xrange(len(timestamps)):
        arr[i] = datetime_to_millis(timestamps[i])
    return DateTimeIndex(dtmodule.irregular(arr))
Example #8
0
def irregular(timestamps, sc):
    """
    Instantiates an irregular DateTimeIndex.
    
    Parameters
    ----------
        timestamps : a Pandas DateTimeIndex, or an array of strings, longs (nanos from epoch), Pandas
            Timestamps
        sc : SparkContext
    """
    dtmodule = sc._jvm.com.cloudera.sparkts.__getattr__(
        'DateTimeIndex$').__getattr__('MODULE$')
    arr = sc._gateway.new_array(sc._jvm.long, len(timestamps))
    for i in xrange(len(timestamps)):
        arr[i] = datetime_to_millis(timestamps[i])
    return DateTimeIndex(dtmodule.irregular(arr))