Ejemplo n.º 1
0
    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-'):
            self.assertEqual(infer_freq(index), gen.freqstr)
        else:
            inf_freq = infer_freq(index)
            self.assertTrue((inf_freq == 'Q-DEC' and
                             gen.freqstr in ('Q', 'Q-DEC', 'Q-SEP', 'Q-JUN',
                                             'Q-MAR'))
                            or
                            (inf_freq == 'Q-NOV' and
                             gen.freqstr in ('Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB'))
                            or
                            (inf_freq == 'Q-OCT' and
                             gen.freqstr in ('Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')))

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)
        if not freq.startswith('Q-'):
            self.assertEqual(infer_freq(index), gen.freqstr)
        else:
            inf_freq = infer_freq(index)
            self.assertTrue((inf_freq == 'Q-DEC' and
                             gen.freqstr in ('Q', 'Q-DEC', 'Q-SEP', 'Q-JUN',
                                             'Q-MAR'))
                            or
                            (inf_freq == 'Q-NOV' and
                             gen.freqstr in ('Q-NOV', 'Q-AUG', 'Q-MAY', 'Q-FEB'))
                            or
                            (inf_freq == 'Q-OCT' and
                             gen.freqstr in ('Q-OCT', 'Q-JUL', 'Q-APR', 'Q-JAN')))
Ejemplo n.º 2
0
    def test_series(self):

        # GH6407
        # inferring series

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

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

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

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

        s = Series(date_range('20130101','20130110'))
        inferred = infer_freq(s)
        self.assertEqual(inferred,'D')
Ejemplo n.º 3
0
    def test_series(self):

        # GH6407
        # inferring series

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

        # a non-convertible string
        self.assertRaises(ValueError, lambda: frequencies.infer_freq(Series(["foo", "bar"])))

        # cannot infer on PeriodIndex
        for freq in [None, "L", "Y"]:
            s = Series(period_range("2013", periods=10, freq=freq))
            self.assertRaises(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)
            self.assertEqual(inferred, freq)

        s = Series(date_range("20130101", "20130110"))
        inferred = frequencies.infer_freq(s)
        self.assertEqual(inferred, "D")
Ejemplo n.º 4
0
def test_series_invalid_type(end):
    # see gh-6407
    msg = "cannot infer freq from a non-convertible dtype on a Series"
    s = Series(np.arange(end))

    with pytest.raises(TypeError, match=msg):
        frequencies.infer_freq(s)
Ejemplo n.º 5
0
    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-"):
            self.assertEqual(frequencies.infer_freq(index), gen.freqstr)
        else:
            inf_freq = frequencies.infer_freq(index)
            self.assertTrue(
                (inf_freq == "Q-DEC" and gen.freqstr in ("Q", "Q-DEC", "Q-SEP", "Q-JUN", "Q-MAR"))
                or (inf_freq == "Q-NOV" and gen.freqstr in ("Q-NOV", "Q-AUG", "Q-MAY", "Q-FEB"))
                or (inf_freq == "Q-OCT" and gen.freqstr in ("Q-OCT", "Q-JUL", "Q-APR", "Q-JAN"))
            )

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)
        if not freq.startswith("Q-"):
            self.assertEqual(frequencies.infer_freq(index), gen.freqstr)
        else:
            inf_freq = frequencies.infer_freq(index)
            self.assertTrue(
                (inf_freq == "Q-DEC" and gen.freqstr in ("Q", "Q-DEC", "Q-SEP", "Q-JUN", "Q-MAR"))
                or (inf_freq == "Q-NOV" and gen.freqstr in ("Q-NOV", "Q-AUG", "Q-MAY", "Q-FEB"))
                or (inf_freq == "Q-OCT" and gen.freqstr in ("Q-OCT", "Q-JUL", "Q-APR", "Q-JAN"))
            )
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
def _check_generated_range(start, periods, freq):
    """
    Check the range generated from a given start, frequency, and period count.

    Parameters
    ----------
    start : str
        The start date.
    periods : int
        The number of periods.
    freq : str
        The frequency of the range.
    """
    freq = freq.upper()

    gen = date_range(start, periods=periods, freq=freq)
    index = DatetimeIndex(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
Ejemplo n.º 8
0
def test_string_datetime_like_compat():
    # see gh-6463
    data = ["2004-01", "2004-02", "2004-03", "2004-04"]

    expected = frequencies.infer_freq(data)
    result = frequencies.infer_freq(Index(data))

    assert result == expected
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    def test_invalid_index_types(self):

        # test all index types
        for i in [tm.makeIntIndex(10), tm.makeFloatIndex(10), tm.makePeriodIndex(10)]:
            self.assertRaises(TypeError, lambda: infer_freq(i))

        for i in [tm.makeStringIndex(10), tm.makeUnicodeIndex(10)]:
            self.assertRaises(ValueError, lambda: infer_freq(i))
Ejemplo n.º 11
0
def test_invalid_index_types_unicode(idx):
    # see gh-10822
    #
    # Odd error message on conversions to datetime for unicode.
    msg = "Unknown string format"

    with pytest.raises(ValueError, match=msg):
        frequencies.infer_freq(idx)
Ejemplo n.º 12
0
def test_series_period_index(freq):
    # see gh-6407
    #
    # Cannot infer on PeriodIndex
    msg = "cannot infer freq from a non-convertible dtype on a Series"
    s = Series(period_range("2013", periods=10, freq=freq))

    with pytest.raises(TypeError, match=msg):
        frequencies.infer_freq(s)
Ejemplo n.º 13
0
    def _check_generated_range(self, start, freq):
        freq = freq.upper()

        gen = date_range(start, periods=7, freq=freq)
        index = _dti(gen.values)
        self.assert_(infer_freq(index) == gen.freqstr)

        gen = date_range(start, periods=5, freq=freq)
        index = _dti(gen.values)
        self.assert_(infer_freq(index) == gen.freqstr)
Ejemplo n.º 14
0
    def test_invalid_index_types(self):

        # test all index types
        for i in [tm.makeIntIndex(10), tm.makeFloatIndex(10), tm.makePeriodIndex(10)]:
            self.assertRaises(TypeError, lambda: frequencies.infer_freq(i))

        # GH 10822
        # odd error message on conversions to datetime for unicode
        if not is_platform_windows():
            for i in [tm.makeStringIndex(10), tm.makeUnicodeIndex(10)]:
                self.assertRaises(ValueError, lambda: frequencies.infer_freq(i))
Ejemplo n.º 15
0
    def test_non_datetimeindex(self):
        rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])

        vals = rng.to_pydatetime()

        result = infer_freq(vals)
        self.assertEqual(result, rng.inferred_freq)
Ejemplo n.º 16
0
    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
Ejemplo n.º 17
0
    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
            self.assertEqual(infer_freq(index), exp_freq)

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

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta * 7])
        self.assertIsNone(infer_freq(index))
Ejemplo n.º 18
0
    def _check_tick(self, base_delta, code):
        b = 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
            self.assert_(infer_freq(index) == exp_freq)

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

        index = _dti([b + base_delta * j for j in range(3)] + [b + base_delta * 7])
        self.assert_(infer_freq(index) is None)
Ejemplo n.º 19
0
    def test_non_datetimeindex(self):
        rng = _dti(["1/31/2000", "1/31/2001", "1/31/2002"])

        vals = rng.to_pydatetime()

        result = frequencies.infer_freq(vals)
        self.assertEqual(result, rng.inferred_freq)
Ejemplo n.º 20
0
def test_infer_freq_delta(base_delta_code_pair, count):
    b = Timestamp(datetime.now())
    base_delta, code = base_delta_code_pair

    inc = base_delta * count
    index = DatetimeIndex([b + inc * j for j in range(3)])

    exp_freq = "%d%s" % (count, code) if count > 1 else code
    assert frequencies.infer_freq(index) == exp_freq
Ejemplo n.º 21
0
    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
            self.assertEqual(frequencies.infer_freq(index), exp_freq)

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

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

        self.assertIsNone(frequencies.infer_freq(index))
Ejemplo n.º 22
0
 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
Ejemplo n.º 23
0
    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
Ejemplo n.º 24
0
def test_infer_freq_delta(base_delta_code_pair, count):
    b = Timestamp(datetime.now())
    base_delta, code = base_delta_code_pair

    inc = base_delta * count
    index = DatetimeIndex([b + inc * j for j in range(3)])

    exp_freq = "{count:d}{code}".format(count=count,
                                        code=code) if count > 1 else code
    assert frequencies.infer_freq(index) == exp_freq
Ejemplo n.º 25
0
 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 infer_freq(self)
     except ValueError:
         return None
Ejemplo n.º 26
0
def _check_generated_range(start, periods, freq):
    """
    Check the range generated from a given start, frequency, and period count.

    Parameters
    ----------
    start : str
        The start date.
    periods : int
        The number of periods.
    freq : str
        The frequency of the range.
    """
    freq = freq.upper()

    gen = date_range(start, periods=periods, freq=freq)
    index = DatetimeIndex(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
Ejemplo n.º 27
0
    def test_series(self):

        # GH6407
        # inferring series

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

        # a non-convertible string
        self.assertRaises(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))
            self.assertRaises(TypeError, lambda : frequencies.infer_freq(s))
        for freq in ['Y']:
            with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
                s = Series(period_range('2013',periods=10,freq=freq))
            self.assertRaises(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)
            self.assertEqual(inferred,freq)

        s = Series(date_range('20130101','20130110'))
        inferred = frequencies.infer_freq(s)
        self.assertEqual(inferred,'D')
Ejemplo n.º 28
0
    def test_series(self):

        # GH6407
        # inferring series

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

        # a non-convertible string
        self.assertRaises(
            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))
            self.assertRaises(TypeError, lambda: frequencies.infer_freq(s))
        for freq in ['Y']:
            with tm.assert_produces_warning(FutureWarning):
                s = Series(period_range('2013', periods=10, freq=freq))
            self.assertRaises(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)
            self.assertEqual(inferred, freq)

        s = Series(date_range('20130101', '20130110'))
        inferred = frequencies.infer_freq(s)
        self.assertEqual(inferred, 'D')
Ejemplo n.º 29
0
    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))
        for freq in ['Y']:

            msg = frequencies._INVALID_FREQ_ERROR
            with tm.assert_raises_regex(ValueError, msg):
                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'
Ejemplo n.º 30
0
    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))
        for freq in ['Y']:

            msg = frequencies._INVALID_FREQ_ERROR
            with tm.assert_raises_regex(ValueError, msg):
                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'
Ejemplo n.º 31
0
def test_raise_if_too_few():
    index = DatetimeIndex(["12/31/1998", "1/3/1999"])
    msg = "Need at least 3 dates to infer frequency"

    with pytest.raises(ValueError, match=msg):
        frequencies.infer_freq(index)
Ejemplo n.º 32
0
 def inferred_freq(self):
     try:
         return infer_freq(self)
     except ValueError:
         return None
Ejemplo n.º 33
0
    def test_string_datetimelike_compat(self):

        # GH 6463
        expected = infer_freq(['2004-01', '2004-02', '2004-03', '2004-04'])
        result = infer_freq(Index(['2004-01', '2004-02', '2004-03', '2004-04']))
        self.assertEqual(result,expected)
Ejemplo n.º 34
0
 def test_business_daily(self):
     index = _dti(['12/31/1998', '1/3/1999', '1/4/1999'])
     self.assertEqual(infer_freq(index), 'B')
Ejemplo n.º 35
0
 def test_non_datetimeindex(self):
     dates = to_datetime(['1/1/2000', '1/2/2000', '1/3/2000'])
     self.assertEqual(infer_freq(dates), 'D')
Ejemplo n.º 36
0
 def test_non_datetimeindex(self):
     dates = to_datetime(['1/1/2000', '1/2/2000', '1/3/2000'])
     self.assert_(infer_freq(dates) == 'D')
Ejemplo n.º 37
0
 def test_business_daily(self):
     index = _dti(['12/31/1998', '1/3/1999', '1/4/1999'])
     self.assert_(infer_freq(index) == 'B')
Ejemplo n.º 38
0
def test_week_of_month_fake():
    # 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"
Ejemplo n.º 39
0
def test_infer_freq_custom(base_delta_code_pair, constructor):
    b = Timestamp(datetime.now())
    base_delta, _ = base_delta_code_pair

    index = constructor(b, base_delta)
    assert frequencies.infer_freq(index) is None
Ejemplo n.º 40
0
def test_non_datetime_index():
    dates = to_datetime(["1/1/2000", "1/2/2000", "1/3/2000"])
    assert frequencies.infer_freq(dates) == "D"
Ejemplo n.º 41
0
def test_fifth_week_of_month_infer():
    # see gh-9425
    #
    # Only attempt to infer up to WOM-4.
    index = DatetimeIndex(["2014-03-31", "2014-06-30", "2015-03-30"])
    assert frequencies.infer_freq(index) is None
Ejemplo n.º 42
0
def test_day_corner():
    index = DatetimeIndex(["1/1/2000", "1/2/2000", "1/3/2000"])
    assert frequencies.infer_freq(index) == "D"
Ejemplo n.º 43
0
def test_business_daily_look_alike():
    # see gh-16624
    #
    # Do not infer "B when "weekend" (2-day gap) in wrong place.
    index = DatetimeIndex(["12/31/1998", "1/3/1999", "1/4/1999"])
    assert frequencies.infer_freq(index) is None
Ejemplo n.º 44
0
def test_business_daily():
    index = DatetimeIndex(["01/01/1999", "1/4/1999", "1/5/1999"])
    assert frequencies.infer_freq(index) == "B"
Ejemplo n.º 45
0
 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
Ejemplo n.º 46
0
 def test_non_datetimeindex(self):
     dates = to_datetime(['1/1/2000', '1/2/2000', '1/3/2000'])
     assert frequencies.infer_freq(dates) == 'D'
Ejemplo n.º 47
0
 def test_business_daily(self):
     index = _dti(['01/01/1999', '1/4/1999', '1/5/1999'])
     assert frequencies.infer_freq(index) == 'B'
Ejemplo n.º 48
0
def test_non_datetime_index2():
    rng = DatetimeIndex(["1/31/2000", "1/31/2001", "1/31/2002"])
    vals = rng.to_pydatetime()

    result = frequencies.infer_freq(vals)
    assert result == rng.inferred_freq
Ejemplo n.º 49
0
 def test_day_corner(self):
     index = _dti(['1/1/2000', '1/2/2000', '1/3/2000'])
     self.assert_(infer_freq(index) == 'D')
Ejemplo n.º 50
0
def test_invalid_index_types(idx):
    msg = ("(cannot infer freq from a non-convertible)|"
           "(Check the `freq` attribute instead of using infer_freq)")

    with pytest.raises(TypeError, match=msg):
        frequencies.infer_freq(idx)
Ejemplo n.º 51
0
def test_business_daily():
    index = DatetimeIndex(["01/01/1999", "1/4/1999", "1/5/1999"])
    assert frequencies.infer_freq(index) == "B"
Ejemplo n.º 52
0
def test_series():
    # see gh-6407
    s = Series(date_range("20130101", "20130110"))
    inferred = frequencies.infer_freq(s)
    assert inferred == "D"
Ejemplo n.º 53
0
 def test_day_corner(self):
     index = _dti(['1/1/2000', '1/2/2000', '1/3/2000'])
     self.assertEqual(infer_freq(index), 'D')
Ejemplo n.º 54
0
def test_series_inconvertible_string():
    # see gh-6407
    msg = "Unknown string format"

    with pytest.raises(ValueError, match=msg):
        frequencies.infer_freq(Series(["foo", "bar"]))
Ejemplo n.º 55
0
 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 infer_freq(index) != 'WOM-4TUE'
Ejemplo n.º 56
0
def test_series_datetime_index(freq):
    s = Series(date_range("20130101", periods=10, freq=freq))
    inferred = frequencies.infer_freq(s)
    assert inferred == freq
Ejemplo n.º 57
0
 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 infer_freq(index) != 'WOM-4TUE'
Ejemplo n.º 58
0
 def test_day_corner(self):
     index = _dti(['1/1/2000', '1/2/2000', '1/3/2000'])
     assert frequencies.infer_freq(index) == 'D'
Ejemplo n.º 59
0
def test_raise_if_period_index():
    index = period_range(start="1/1/1990", periods=20, freq="M")
    msg = "Check the `freq` attribute instead of using infer_freq"

    with pytest.raises(TypeError, match=msg):
        frequencies.infer_freq(index)
Ejemplo n.º 60
0
 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