Python pandas.tseries.frequencies.get_freq() Examples

The following are 30 code examples of pandas.tseries.frequencies.get_freq(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.tseries.frequencies , or try the search function .
Example #1
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_freq_to_reso(self):
        Reso = frequencies.Resolution

        assert Reso.get_str_from_freq('A') == 'year'
        assert Reso.get_str_from_freq('Q') == 'quarter'
        assert Reso.get_str_from_freq('M') == 'month'
        assert Reso.get_str_from_freq('D') == 'day'
        assert Reso.get_str_from_freq('H') == 'hour'
        assert Reso.get_str_from_freq('T') == 'minute'
        assert Reso.get_str_from_freq('S') == 'second'
        assert Reso.get_str_from_freq('L') == 'millisecond'
        assert Reso.get_str_from_freq('U') == 'microsecond'
        assert Reso.get_str_from_freq('N') == 'nanosecond'

        for freq in ['A', 'Q', 'M', 'D', 'H', 'T', 'S', 'L', 'U', 'N']:
            # check roundtrip
            result = Reso.get_freq(Reso.get_str_from_freq(freq))
            assert freq == result

        for freq in ['D', 'H', 'T', 'S', 'L', 'U']:
            result = Reso.get_freq(Reso.get_str(Reso.get_reso_from_freq(freq)))
            assert freq == result 
Example #2
Source File: _converter.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def get_finder(freq):
    if isinstance(freq, compat.string_types):
        freq = frequencies.get_freq(freq)
    fgroup = frequencies.get_freq_group(freq)

    if fgroup == FreqGroup.FR_ANN:
        return _annual_finder
    elif fgroup == FreqGroup.FR_QTR:
        return _quarterly_finder
    elif freq == FreqGroup.FR_MTH:
        return _monthly_finder
    elif ((freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK):
        return _daily_finder
    else:  # pragma: no cover
        errmsg = "Unsupported frequency: %s" % (freq)
        raise NotImplementedError(errmsg) 
Example #3
Source File: _converter.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_finder(freq):
    if isinstance(freq, compat.string_types):
        freq = frequencies.get_freq(freq)
    fgroup = frequencies.get_freq_group(freq)

    if fgroup == FreqGroup.FR_ANN:
        return _annual_finder
    elif fgroup == FreqGroup.FR_QTR:
        return _quarterly_finder
    elif freq == FreqGroup.FR_MTH:
        return _monthly_finder
    elif ((freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK):
        return _daily_finder
    else:  # pragma: no cover
        errmsg = "Unsupported frequency: %s" % (freq)
        raise NotImplementedError(errmsg) 
Example #4
Source File: test_tools.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_period_ordinal_business_day(self):
        # Thursday
        assert period_ordinal(2013, 10, 3, 0,
                              0, 0, 0, 0, get_freq('B')) == 11415
        # Friday
        assert period_ordinal(2013, 10, 4, 0,
                              0, 0, 0, 0, get_freq('B')) == 11416
        # Saturday
        assert period_ordinal(2013, 10, 5, 0,
                              0, 0, 0, 0, get_freq('B')) == 11417
        # Sunday
        assert period_ordinal(2013, 10, 6, 0,
                              0, 0, 0, 0, get_freq('B')) == 11417
        # Monday
        assert period_ordinal(2013, 10, 7, 0,
                              0, 0, 0, 0, get_freq('B')) == 11417
        # Tuesday
        assert period_ordinal(2013, 10, 8, 0,
                              0, 0, 0, 0, get_freq('B')) == 11418 
Example #5
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_freq_code(self):
        assert frequencies.get_freq('A') == 1000
        assert frequencies.get_freq('3A') == 1000
        assert frequencies.get_freq('-1A') == 1000

        assert frequencies.get_freq('Y') == 1000
        assert frequencies.get_freq('3Y') == 1000
        assert frequencies.get_freq('-1Y') == 1000

        assert frequencies.get_freq('W') == 4000
        assert frequencies.get_freq('W-MON') == 4001
        assert frequencies.get_freq('W-FRI') == 4005

        for freqstr, code in compat.iteritems(frequencies._period_code_map):
            result = frequencies.get_freq(freqstr)
            assert result == code

            result = frequencies.get_freq_group(freqstr)
            assert result == code // 1000 * 1000

            result = frequencies.get_freq_group(code)
            assert result == code // 1000 * 1000 
Example #6
Source File: _converter.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def get_finder(freq):
    if isinstance(freq, compat.string_types):
        freq = frequencies.get_freq(freq)
    fgroup = resolution.get_freq_group(freq)

    if fgroup == FreqGroup.FR_ANN:
        return _annual_finder
    elif fgroup == FreqGroup.FR_QTR:
        return _quarterly_finder
    elif freq == FreqGroup.FR_MTH:
        return _monthly_finder
    elif ((freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK):
        return _daily_finder
    else:  # pragma: no cover
        errmsg = "Unsupported frequency: {freq}".format(freq=freq)
        raise NotImplementedError(errmsg) 
Example #7
Source File: converter.py    From Computable with MIT License 6 votes vote down vote up
def get_finder(freq):
    if isinstance(freq, compat.string_types):
        freq = frequencies.get_freq(freq)
    fgroup = frequencies.get_freq_group(freq)

    if fgroup == FreqGroup.FR_ANN:
        return _annual_finder
    elif fgroup == FreqGroup.FR_QTR:
        return _quarterly_finder
    elif freq == FreqGroup.FR_MTH:
        return _monthly_finder
    elif ((freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK):
        return _daily_finder
    else:  # pragma: no cover
        errmsg = "Unsupported frequency: %s" % (freq)
        raise NotImplementedError(errmsg) 
Example #8
Source File: test_frequencies.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_freq_code(self):
        assert frequencies.get_freq('A') == 1000
        assert frequencies.get_freq('3A') == 1000
        assert frequencies.get_freq('-1A') == 1000

        assert frequencies.get_freq('Y') == 1000
        assert frequencies.get_freq('3Y') == 1000
        assert frequencies.get_freq('-1Y') == 1000

        assert frequencies.get_freq('W') == 4000
        assert frequencies.get_freq('W-MON') == 4001
        assert frequencies.get_freq('W-FRI') == 4005

        for freqstr, code in compat.iteritems(_period_code_map):
            result = frequencies.get_freq(freqstr)
            assert result == code

            result = resolution.get_freq_group(freqstr)
            assert result == code // 1000 * 1000

            result = resolution.get_freq_group(code)
            assert result == code // 1000 * 1000 
Example #9
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_freq_code(self):
        assert frequencies.get_freq('A') == 1000
        assert frequencies.get_freq('3A') == 1000
        assert frequencies.get_freq('-1A') == 1000

        assert frequencies.get_freq('Y') == 1000
        assert frequencies.get_freq('3Y') == 1000
        assert frequencies.get_freq('-1Y') == 1000

        assert frequencies.get_freq('W') == 4000
        assert frequencies.get_freq('W-MON') == 4001
        assert frequencies.get_freq('W-FRI') == 4005

        for freqstr, code in compat.iteritems(_period_code_map):
            result = frequencies.get_freq(freqstr)
            assert result == code

            result = resolution.get_freq_group(freqstr)
            assert result == code // 1000 * 1000

            result = resolution.get_freq_group(code)
            assert result == code // 1000 * 1000 
Example #10
Source File: _converter.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def get_finder(freq):
    if isinstance(freq, compat.string_types):
        freq = frequencies.get_freq(freq)
    fgroup = resolution.get_freq_group(freq)

    if fgroup == FreqGroup.FR_ANN:
        return _annual_finder
    elif fgroup == FreqGroup.FR_QTR:
        return _quarterly_finder
    elif freq == FreqGroup.FR_MTH:
        return _monthly_finder
    elif ((freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK):
        return _daily_finder
    else:  # pragma: no cover
        errmsg = "Unsupported frequency: {freq}".format(freq=freq)
        raise NotImplementedError(errmsg) 
Example #11
Source File: _converter.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 base=1, quarter=1, month=1, day=1, plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.freq = freq
        self.base = base
        (self.quarter, self.month, self.day) = (quarter, month, day)
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #12
Source File: _converter.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.format = None
        self.freq = freq
        self.locs = []
        self.formatdict = None
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #13
Source File: _converter.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 base=1, quarter=1, month=1, day=1, plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.freq = freq
        self.base = base
        (self.quarter, self.month, self.day) = (quarter, month, day)
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #14
Source File: _timeseries.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _use_dynamic_x(ax, data):
    freq = _get_index_freq(data)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)
    freq = frequencies.get_period_alias(freq)

    if freq is None:
        return False

    # hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, DatetimeIndex):
        base = frequencies.get_freq(freq)
        x = data.index
        if (base <= frequencies.FreqGroup.FR_DAY):
            return x[:1].is_normalized
        return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
    return True 
Example #15
Source File: test_tools.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_period_ordinal_week(self):
        assert period_ordinal(1970, 1, 4, 0, 0, 0, 0, 0, get_freq('W')) == 1
        assert period_ordinal(1970, 1, 5, 0, 0, 0, 0, 0, get_freq('W')) == 2
        assert period_ordinal(2013, 10, 6, 0,
                              0, 0, 0, 0, get_freq('W')) == 2284
        assert period_ordinal(2013, 10, 7, 0,
                              0, 0, 0, 0, get_freq('W')) == 2285 
Example #16
Source File: test_tools.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_intraday_conversion_factors(self):
        assert period_asfreq(1, get_freq('D'), get_freq('H'), False) == 24
        assert period_asfreq(1, get_freq('D'), get_freq('T'), False) == 1440
        assert period_asfreq(1, get_freq('D'), get_freq('S'), False) == 86400
        assert period_asfreq(1, get_freq('D'),
                             get_freq('L'), False) == 86400000
        assert period_asfreq(1, get_freq('D'),
                             get_freq('U'), False) == 86400000000
        assert period_asfreq(1, get_freq('D'),
                             get_freq('N'), False) == 86400000000000

        assert period_asfreq(1, get_freq('H'), get_freq('T'), False) == 60
        assert period_asfreq(1, get_freq('H'), get_freq('S'), False) == 3600
        assert period_asfreq(1, get_freq('H'),
                             get_freq('L'), False) == 3600000
        assert period_asfreq(1, get_freq('H'),
                             get_freq('U'), False) == 3600000000
        assert period_asfreq(1, get_freq('H'),
                             get_freq('N'), False) == 3600000000000

        assert period_asfreq(1, get_freq('T'), get_freq('S'), False) == 60
        assert period_asfreq(1, get_freq('T'), get_freq('L'), False) == 60000
        assert period_asfreq(1, get_freq('T'),
                             get_freq('U'), False) == 60000000
        assert period_asfreq(1, get_freq('T'),
                             get_freq('N'), False) == 60000000000

        assert period_asfreq(1, get_freq('S'), get_freq('L'), False) == 1000
        assert period_asfreq(1, get_freq('S'),
                             get_freq('U'), False) == 1000000
        assert period_asfreq(1, get_freq('S'),
                             get_freq('N'), False) == 1000000000

        assert period_asfreq(1, get_freq('L'), get_freq('U'), False) == 1000
        assert period_asfreq(1, get_freq('L'),
                             get_freq('N'), False) == 1000000

        assert period_asfreq(1, get_freq('U'), get_freq('N'), False) == 1000 
Example #17
Source File: _timeseries.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def _use_dynamic_x(ax, data):
    freq = _get_index_freq(data)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)
    freq = frequencies.get_period_alias(freq)

    if freq is None:
        return False

    # hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, DatetimeIndex):
        base = frequencies.get_freq(freq)
        x = data.index
        if (base <= frequencies.FreqGroup.FR_DAY):
            return x[:1].is_normalized
        return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
    return True 
Example #18
Source File: _converter.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.format = None
        self.freq = freq
        self.locs = []
        self.formatdict = None
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #19
Source File: _converter.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 base=1, quarter=1, month=1, day=1, plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.freq = freq
        self.base = base
        (self.quarter, self.month, self.day) = (quarter, month, day)
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #20
Source File: _timeseries.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _use_dynamic_x(ax, data):
    freq = _get_index_freq(data)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)
    freq = frequencies.get_period_alias(freq)

    if freq is None:
        return False

    # hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, DatetimeIndex):
        base = frequencies.get_freq(freq)
        x = data.index
        if (base <= frequencies.FreqGroup.FR_DAY):
            return x[:1].is_normalized
        return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
    return True 
Example #21
Source File: _converter.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.format = None
        self.freq = freq
        self.locs = []
        self.formatdict = None
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #22
Source File: _converter.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 base=1, quarter=1, month=1, day=1, plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.freq = freq
        self.base = base
        (self.quarter, self.month, self.day) = (quarter, month, day)
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #23
Source File: plotting.py    From Computable with MIT License 5 votes vote down vote up
def _no_base(self, freq):
        # hack this for 0.10.1, creating more technical debt...sigh
        from pandas.core.frame import DataFrame
        if (isinstance(self.data, (Series, DataFrame))
            and isinstance(self.data.index, DatetimeIndex)):
            import pandas.tseries.frequencies as freqmod
            base = freqmod.get_freq(freq)
            x = self.data.index
            if (base <= freqmod.FreqGroup.FR_DAY):
                return x[:1].is_normalized

            return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
        return True 
Example #24
Source File: test_tslib.py    From Computable with MIT License 5 votes vote down vote up
def test_period_ordinal_business_day(self):
        # Thursday
        self.assertEqual(11415, period_ordinal(2013, 10, 3, 0, 0, 0, 0, 0, get_freq('B')))
        # Friday
        self.assertEqual(11416, period_ordinal(2013, 10, 4, 0, 0, 0, 0, 0, get_freq('B')))
        # Saturday
        self.assertEqual(11417, period_ordinal(2013, 10, 5, 0, 0, 0, 0, 0, get_freq('B')))
        # Sunday
        self.assertEqual(11417, period_ordinal(2013, 10, 6, 0, 0, 0, 0, 0, get_freq('B')))
        # Monday
        self.assertEqual(11417, period_ordinal(2013, 10, 7, 0, 0, 0, 0, 0, get_freq('B')))
        # Tuesday
        self.assertEqual(11418, period_ordinal(2013, 10, 8, 0, 0, 0, 0, 0, get_freq('B'))) 
Example #25
Source File: test_tslib.py    From Computable with MIT License 5 votes vote down vote up
def test_period_ordinal_start_values(self):
        # information for 1.1.1970
        self.assertEqual(0, period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('Y')))
        self.assertEqual(0, period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('M')))
        self.assertEqual(1, period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('W')))
        self.assertEqual(0, period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('D')))
        self.assertEqual(0, period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('B'))) 
Example #26
Source File: test_tslib.py    From Computable with MIT License 5 votes vote down vote up
def test_intraday_conversion_factors(self):
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('H'), False), 24)
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('T'), False), 1440)
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('S'), False), 86400)
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('L'), False), 86400000)
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('U'), False), 86400000000)
        self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('N'), False), 86400000000000)

        self.assertEqual(period_asfreq(1, get_freq('H'), get_freq('T'), False), 60)
        self.assertEqual(period_asfreq(1, get_freq('H'), get_freq('S'), False), 3600)
        self.assertEqual(period_asfreq(1, get_freq('H'), get_freq('L'), False), 3600000)
        self.assertEqual(period_asfreq(1, get_freq('H'), get_freq('U'), False), 3600000000)
        self.assertEqual(period_asfreq(1, get_freq('H'), get_freq('N'), False), 3600000000000)

        self.assertEqual(period_asfreq(1, get_freq('T'), get_freq('S'), False), 60)
        self.assertEqual(period_asfreq(1, get_freq('T'), get_freq('L'), False), 60000)
        self.assertEqual(period_asfreq(1, get_freq('T'), get_freq('U'), False), 60000000)
        self.assertEqual(period_asfreq(1, get_freq('T'), get_freq('N'), False), 60000000000)

        self.assertEqual(period_asfreq(1, get_freq('S'), get_freq('L'), False), 1000)
        self.assertEqual(period_asfreq(1, get_freq('S'), get_freq('U'), False), 1000000)
        self.assertEqual(period_asfreq(1, get_freq('S'), get_freq('N'), False), 1000000000)

        self.assertEqual(period_asfreq(1, get_freq('L'), get_freq('U'), False), 1000)
        self.assertEqual(period_asfreq(1, get_freq('L'), get_freq('N'), False), 1000000)

        self.assertEqual(period_asfreq(1, get_freq('U'), get_freq('N'), False), 1000) 
Example #27
Source File: converter.py    From Computable with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.format = None
        self.freq = freq
        self.locs = []
        self.formatdict = None
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #28
Source File: converter.py    From Computable with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 base=1, quarter=1, month=1, day=1, plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.freq = freq
        self.base = base
        (self.quarter, self.month, self.day) = (quarter, month, day)
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq) 
Example #29
Source File: _timeseries.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def _use_dynamic_x(ax, data):
    freq = _get_index_freq(data)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    if isinstance(freq, DateOffset):
        freq = freq.rule_code
    else:
        freq = frequencies.get_base_alias(freq)
    freq = frequencies.get_period_alias(freq)

    if freq is None:
        return False

    # hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, DatetimeIndex):
        base = frequencies.get_freq(freq)
        x = data.index
        if (base <= frequencies.FreqGroup.FR_DAY):
            return x[:1].is_normalized
        return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
    return True 
Example #30
Source File: _converter.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
                 plot_obj=None):
        if isinstance(freq, compat.string_types):
            freq = frequencies.get_freq(freq)
        self.format = None
        self.freq = freq
        self.locs = []
        self.formatdict = None
        self.isminor = minor_locator
        self.isdynamic = dynamic_mode
        self.offset = 0
        self.plot_obj = plot_obj
        self.finder = get_finder(freq)