Example #1
0
def fromarrays(arraylist, dates=None, start_date=None, freq='U',
               fill_value=None, autosort=True,
               dtype=None, shape=None, formats=None,
               names=None, titles=None, aligned=False, byteorder=None,):
    """
    Creates a mrecarray from a (flat) list of masked arrays.

    Parameters
    ----------
    arraylist : array_like
        A list of (masked) arrays. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dates : {DateArray}, optional
        Array of dates corresponding to each entry.
        If None, a DateArray is constructed from `start_date` and the length
        of the arrays in the input list.
    start_date : {Date}, optional
        First date of the output.
        This parameter is inly needed if `dates` is None.
    freq : {var}, optional
        Frequency of the DateArray
    fill_value : {var}, optional
        Value used to fill in the masked values when necessary.
        If None, a default based on the datatype is used.
    autosort : {True, False}, optional
        Whether the records should be sorted chronologically.

    See Also
    --------
    numpy.core.records.fromarrays : equivalent function for ndarrays
        The docstring of this function describes the additional optional
        input parameters.
    

    Notes
    -----
    * Lists of tuples should be preferred over lists of lists as inputs 
      for faster processing.
    """
    _array = mrecfromarrays(arraylist, dtype=dtype, shape=shape, formats=formats,
                            names=names, titles=titles, aligned=aligned,
                            byteorder=byteorder, fill_value=fill_value)
    _dates = _getdates(dates, length=len(_array), start_date=start_date, 
                       freq=freq)
#    if _dates._unsorted is not None:
#        idx = _dates._unsorted
#        _array = _array[idx]
#        _dates._unsorted = None
    result = _array.view(trecarray)
    result._dates = _dates
    if autosort:
        result.sort_chronologically()
    return result
Example #2
0
def fromrecords(
    reclist,
    dates=None,
    freq=None,
    start_date=None,
    fill_value=None,
    mask=nomask,
    autosort=True,
    dtype=None,
    shape=None,
    formats=None,
    names=None,
    titles=None,
    aligned=False,
    byteorder=None,
):
    """
    Creates a TimeSeriesRecords from a list of records.

    The data in the same field can be heterogeneous, they will be promoted
    to the highest data type.  This method is intended for creating
    smaller record arrays.  If used to create large array without formats
    defined, it can be slow.

    If formats is None, then this will auto-detect formats. Use a list of
    tuples rather than a list of lists for faster processing.


    Parameters
    ----------
    reclist : array_like
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dates : {DateArray}, optional
        Array of dates corresponding to each entry.
        If None, a DateArray is constructed from `start_date` and the length
        of the arrays in the input list.
    freq : {var}, optional
        Frequency of the DateArray
    start_date : {Date}, optional
        First date of the output.
        This parameter is inly needed if `dates` is None.
    fill_value : {var}, optional
        Value used to fill in the masked values when necessary.
        If None, a default based on the datatype is used.
    autosort : {True, False}, optional
        Whether the records should be sorted chronologically.
        

    See Also
    --------
    numpy.core.records.fromrecords : equivalent function for ndarrays


    """
    _data = mrecfromrecords(
        reclist,
        dtype=dtype,
        shape=shape,
        formats=formats,
        names=names,
        titles=titles,
        aligned=aligned,
        byteorder=byteorder,
        mask=mask,
    )
    _dtype = _data.dtype
    # Check the names for a '_dates' .................
    newdates = None
    _names = list(_dtype.names)
    reserved = [n for n in _names if n.lower() in ["dates", "_dates"]]
    if len(reserved) > 0:
        newdates = _data[reserved[-1]]
        [_names.remove(n) for n in reserved]
        _dtype = np.dtype([t for t in _dtype.descr if t[0] not in reserved])
        _data = mrecfromarrays([_data[n] for n in _names], dtype=_dtype)
    #
    if dates is None:
        dates = getattr(reclist, "_dates", None)
    _dates = _getdates(dates=dates, newdates=newdates, length=len(_data), freq=freq, start_date=start_date)
    #
    result = _data.view(trecarray)
    result._dates = _dates
    if autosort:
        result.sort_chronologically()
    return result
Example #3
0
def fromrecords(reclist, dates=None, freq=None, start_date=None,
                fill_value=None, mask=nomask, autosort=True,
                dtype=None, shape=None, formats=None, names=None,
                titles=None, aligned=False, byteorder=None):
    """
    Creates a TimeSeriesRecords from a list of records.

    The data in the same field can be heterogeneous, they will be promoted
    to the highest data type.  This method is intended for creating
    smaller record arrays.  If used to create large array without formats
    defined, it can be slow.

    If formats is None, then this will auto-detect formats. Use a list of
    tuples rather than a list of lists for faster processing.


    Parameters
    ----------
    reclist : array_like
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dates : {DateArray}, optional
        Array of dates corresponding to each entry.
        If None, a DateArray is constructed from `start_date` and the length
        of the arrays in the input list.
    freq : {var}, optional
        Frequency of the DateArray
    start_date : {Date}, optional
        First date of the output.
        This parameter is inly needed if `dates` is None.
    fill_value : {var}, optional
        Value used to fill in the masked values when necessary.
        If None, a default based on the datatype is used.
    autosort : {True, False}, optional
        Whether the records should be sorted chronologically.
        

    See Also
    --------
    numpy.core.records.fromrecords : equivalent function for ndarrays


    """
    _data = mrecfromrecords(reclist, dtype=dtype, shape=shape, formats=formats,
                            names=names, titles=titles, aligned=aligned,
                            byteorder=byteorder, mask=mask)
    _dtype = _data.dtype
    # Check the names for a '_dates' .................
    newdates = None
    _names = list(_dtype.names)
    reserved = [n for n in _names if n.lower() in ['dates', '_dates']]
    if len(reserved) > 0:
        newdates = _data[reserved[-1]]
        [_names.remove(n) for n in reserved]
        _dtype = np.dtype([t for t in _dtype.descr \
                                    if t[0] not in reserved ])
        _data = mrecfromarrays([_data[n] for n in _names], dtype=_dtype)
    #
    if dates is None:
        dates = getattr(reclist, '_dates', None)
    _dates = _getdates(dates=dates, newdates=newdates, length=len(_data),
                       freq=freq, start_date=start_date)
    #
    result = _data.view(trecarray)
    result._dates = _dates
    if autosort:
        result.sort_chronologically()
    return result