Python pandas.tseries.frequencies.infer_freq() Examples

The following are 30 code examples of pandas.tseries.frequencies.infer_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 predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def _check_tick(self, base_delta, code):
        b = Timestamp(datetime.now())
        for i in range(1, 5):
            inc = base_delta * i
            index = _dti([b + inc * j for j in range(3)])
            if i > 1:
                exp_freq = '%d%s' % (i, code)
            else:
                exp_freq = code
            assert frequencies.infer_freq(index) == exp_freq

        index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
            3)])
        assert frequencies.infer_freq(index) is None

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
                                                               7])

        assert frequencies.infer_freq(index) is None 
Example #2
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def _check_tick(self, base_delta, code):
        b = Timestamp(datetime.now())
        for i in range(1, 5):
            inc = base_delta * i
            index = _dti([b + inc * j for j in range(3)])
            if i > 1:
                exp_freq = '%d%s' % (i, code)
            else:
                exp_freq = code
            assert frequencies.infer_freq(index) == exp_freq

        index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
            3)])
        assert frequencies.infer_freq(index) is None

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
                                                               7])

        assert frequencies.infer_freq(index) is None 
Example #3
Source File: test_frequencies.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def _check_tick(self, base_delta, code):
        b = Timestamp(datetime.now())
        for i in range(1, 5):
            inc = base_delta * i
            index = _dti([b + inc * j for j in range(3)])
            if i > 1:
                exp_freq = '%d%s' % (i, code)
            else:
                exp_freq = code
            assert frequencies.infer_freq(index) == exp_freq

        index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
            3)])
        assert frequencies.infer_freq(index) is None

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
                                                               7])

        assert frequencies.infer_freq(index) is None 
Example #4
Source File: test_frequencies.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _check_tick(self, base_delta, code):
        b = Timestamp(datetime.now())
        for i in range(1, 5):
            inc = base_delta * i
            index = _dti([b + inc * j for j in range(3)])
            if i > 1:
                exp_freq = '%d%s' % (i, code)
            else:
                exp_freq = code
            assert frequencies.infer_freq(index) == exp_freq

        index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
            3)])
        assert frequencies.infer_freq(index) is None

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
                                                               7])

        assert frequencies.infer_freq(index) is None 
Example #5
Source File: test_frequencies.py    From recruit with Apache License 2.0 6 votes vote down vote up
def _check_tick(self, base_delta, code):
        b = Timestamp(datetime.now())
        for i in range(1, 5):
            inc = base_delta * i
            index = _dti([b + inc * j for j in range(3)])
            if i > 1:
                exp_freq = '%d%s' % (i, code)
            else:
                exp_freq = code
            assert frequencies.infer_freq(index) == exp_freq

        index = _dti([b + base_delta * 7] + [b + base_delta * j for j in range(
            3)])
        assert frequencies.infer_freq(index) is None

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta *
                                                               7])

        assert frequencies.infer_freq(index) is None 
Example #6
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_business_daily(self):
        index = _dti(['01/01/1999', '1/4/1999', '1/5/1999'])
        assert frequencies.infer_freq(index) == 'B' 
Example #7
Source File: test_frequencies.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_series(self):

        # GH6407
        # inferring series

        # invalid type of Series
        for s in [Series(np.arange(10)), Series(np.arange(10.))]:
            pytest.raises(TypeError, lambda: frequencies.infer_freq(s))

        # a non-convertible string
        pytest.raises(ValueError, lambda: frequencies.infer_freq(
            Series(['foo', 'bar'])))

        # cannot infer on PeriodIndex
        for freq in [None, 'L']:
            s = Series(period_range('2013', periods=10, freq=freq))
            pytest.raises(TypeError, lambda: frequencies.infer_freq(s))

        # DateTimeIndex
        for freq in ['M', 'L', 'S']:
            s = Series(date_range('20130101', periods=10, freq=freq))
            inferred = frequencies.infer_freq(s)
            assert inferred == freq

        s = Series(date_range('20130101', '20130110'))
        inferred = frequencies.infer_freq(s)
        assert inferred == 'D' 
Example #8
Source File: test_frequencies.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_string_datetimelike_compat(self):

        # GH 6463
        expected = frequencies.infer_freq(['2004-01', '2004-02', '2004-03',
                                           '2004-04'])
        result = frequencies.infer_freq(Index(['2004-01', '2004-02', '2004-03',
                                               '2004-04']))
        assert result == expected 
Example #9
Source File: test_frequencies.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_non_datetimeindex2(self):
        rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])

        vals = rng.to_pydatetime()

        result = frequencies.infer_freq(vals)
        assert result == rng.inferred_freq 
Example #10
Source File: test_frequencies.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def _check_generated_range(self, start, freq):
        freq = freq.upper()

        gen = date_range(start, periods=7, freq=freq)
        index = _dti(gen.values)
        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')
            assert is_dec_range or is_nov_range or is_oct_range

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)

        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')

            assert is_dec_range or is_nov_range or is_oct_range 
Example #11
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_raise_if_period_index(self):
        index = PeriodIndex(start="1/1/1990", periods=20, freq="M")
        pytest.raises(TypeError, frequencies.infer_freq, index) 
Example #12
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_non_datetimeindex2(self):
        rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])

        vals = rng.to_pydatetime()

        result = frequencies.infer_freq(vals)
        assert result == rng.inferred_freq 
Example #13
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def _check_generated_range(self, start, freq):
        freq = freq.upper()

        gen = date_range(start, periods=7, freq=freq)
        index = _dti(gen.values)
        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')
            assert is_dec_range or is_nov_range or is_oct_range

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)

        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')

            assert is_dec_range or is_nov_range or is_oct_range 
Example #14
Source File: test_frequencies.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_raise_if_period_index(self):
        index = period_range(start="1/1/1990", periods=20, freq="M")
        pytest.raises(TypeError, frequencies.infer_freq, index) 
Example #15
Source File: datetimelike.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def inferred_freq(self):
        """
        Trys to return a string representing a frequency guess,
        generated by infer_freq.  Returns None if it can't autodetect the
        frequency.
        """
        try:
            return frequencies.infer_freq(self)
        except ValueError:
            return None 
Example #16
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_week_of_month_fake(self):
        # All of these dates are on same day of week and are 4 or 5 weeks apart
        index = DatetimeIndex(["2013-08-27", "2013-10-01", "2013-10-29",
                               "2013-11-26"])
        assert frequencies.infer_freq(index) != 'WOM-4TUE' 
Example #17
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_business_daily_look_alike(self):
        # GH 16624, do not infer 'B' when 'weekend' (2-day gap) in wrong place
        index = _dti(['12/31/1998', '1/3/1999', '1/4/1999'])
        assert frequencies.infer_freq(index) is None 
Example #18
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_fifth_week_of_month_infer(self):
        # Only attempts to infer up to WOM-4. See #9425
        index = DatetimeIndex(["2014-03-31", "2014-06-30", "2015-03-30"])
        assert frequencies.infer_freq(index) is None 
Example #19
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_day_corner(self):
        index = _dti(['1/1/2000', '1/2/2000', '1/3/2000'])
        assert frequencies.infer_freq(index) == 'D' 
Example #20
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_business_daily_look_alike(self):
        # GH 16624, do not infer 'B' when 'weekend' (2-day gap) in wrong place
        index = _dti(['12/31/1998', '1/3/1999', '1/4/1999'])
        assert frequencies.infer_freq(index) is None 
Example #21
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_business_daily(self):
        index = _dti(['01/01/1999', '1/4/1999', '1/5/1999'])
        assert frequencies.infer_freq(index) == 'B' 
Example #22
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_raise_if_too_few(self):
        index = _dti(['12/31/1998', '1/3/1999'])
        pytest.raises(ValueError, frequencies.infer_freq, index) 
Example #23
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_raise_if_period_index(self):
        index = PeriodIndex(start="1/1/1990", periods=20, freq="M")
        pytest.raises(TypeError, frequencies.infer_freq, index) 
Example #24
Source File: datetimelike.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def inferred_freq(self):
        """
        Trys to return a string representing a frequency guess,
        generated by infer_freq.  Returns None if it can't autodetect the
        frequency.
        """
        try:
            return frequencies.infer_freq(self)
        except ValueError:
            return None 
Example #25
Source File: datetimelike.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def inferred_freq(self):
        """
        Tryies to return a string representing a frequency guess,
        generated by infer_freq.  Returns None if it can't autodetect the
        frequency.
        """
        try:
            return frequencies.infer_freq(self)
        except ValueError:
            return None 
Example #26
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_series(self):

        # GH6407
        # inferring series

        # invalid type of Series
        for s in [Series(np.arange(10)), Series(np.arange(10.))]:
            pytest.raises(TypeError, lambda: frequencies.infer_freq(s))

        # a non-convertible string
        pytest.raises(ValueError, lambda: frequencies.infer_freq(
            Series(['foo', 'bar'])))

        # cannot infer on PeriodIndex
        for freq in [None, 'L']:
            s = Series(period_range('2013', periods=10, freq=freq))
            pytest.raises(TypeError, lambda: frequencies.infer_freq(s))

        # DateTimeIndex
        for freq in ['M', 'L', 'S']:
            s = Series(date_range('20130101', periods=10, freq=freq))
            inferred = frequencies.infer_freq(s)
            assert inferred == freq

        s = Series(date_range('20130101', '20130110'))
        inferred = frequencies.infer_freq(s)
        assert inferred == 'D' 
Example #27
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_string_datetimelike_compat(self):

        # GH 6463
        expected = frequencies.infer_freq(['2004-01', '2004-02', '2004-03',
                                           '2004-04'])
        result = frequencies.infer_freq(Index(['2004-01', '2004-02', '2004-03',
                                               '2004-04']))
        assert result == expected 
Example #28
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_non_datetimeindex2(self):
        rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])

        vals = rng.to_pydatetime()

        result = frequencies.infer_freq(vals)
        assert result == rng.inferred_freq 
Example #29
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def _check_generated_range(self, start, freq):
        freq = freq.upper()

        gen = date_range(start, periods=7, freq=freq)
        index = _dti(gen.values)
        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')
            assert is_dec_range or is_nov_range or is_oct_range

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)

        if not freq.startswith('Q-'):
            assert frequencies.infer_freq(index) == gen.freqstr
        else:
            inf_freq = frequencies.infer_freq(index)
            is_dec_range = inf_freq == 'Q-DEC' and gen.freqstr in (
                'Q', 'Q-DEC', 'Q-SEP', 'Q-JUN', 'Q-MAR')
            is_nov_range = inf_freq == 'Q-NOV' and gen.freqstr in (
                'Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB')
            is_oct_range = inf_freq == 'Q-OCT' and gen.freqstr in (
                'Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')

            assert is_dec_range or is_nov_range or is_oct_range 
Example #30
Source File: test_frequencies.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_week_of_month_fake(self):
        # All of these dates are on same day of week and are 4 or 5 weeks apart
        index = DatetimeIndex(["2013-08-27", "2013-10-01", "2013-10-29",
                               "2013-11-26"])
        assert frequencies.infer_freq(index) != 'WOM-4TUE'