コード例 #1
0
def _maybe_cache(arg, format, cache, convert_listlike):
    """
    Create a cache of unique dates from an array of dates

    Parameters
    ----------
    arg : integer, float, string, datetime, list, tuple, 1-d array, Series
    format : string
        Strftime format to parse time
    cache : boolean
        True attempts to create a cache of converted values
    convert_listlike : function
        Conversion function to apply on dates

    Returns
    -------
    cache_array : Series
        Cache of converted, unique dates. Can be empty
    """
    from pandas import Series
    cache_array = Series()
    if cache:
        # Perform a quicker unique check
        from pandas import Index
        unique_dates = Index(arg).unique()
        if len(unique_dates) < len(arg):
            cache_dates = convert_listlike(unique_dates.to_numpy(), True,
                                           format)
            cache_array = Series(cache_dates, index=unique_dates)
    return cache_array
コード例 #2
0
ファイル: datetimes.py プロジェクト: bwignall/pandas
def _maybe_cache(arg, format, cache, convert_listlike):
    """
    Create a cache of unique dates from an array of dates

    Parameters
    ----------
    arg : integer, float, string, datetime, list, tuple, 1-d array, Series
    format : string
        Strftime format to parse time
    cache : boolean
        True attempts to create a cache of converted values
    convert_listlike : function
        Conversion function to apply on dates

    Returns
    -------
    cache_array : Series
        Cache of converted, unique dates. Can be empty
    """
    from pandas import Series
    cache_array = Series()
    if cache:
        # Perform a quicker unique check
        from pandas import Index
        unique_dates = Index(arg).unique()
        if len(unique_dates) < len(arg):
            cache_dates = convert_listlike(unique_dates.to_numpy(),
                                           True, format)
            cache_array = Series(cache_dates, index=unique_dates)
    return cache_array