Beispiel #1
0
def test_dti_snap(name, tz):
    dti = DatetimeIndex([
        '1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002', '1/5/2002', '1/6/2002',
        '1/7/2002'
    ],
                        name=name,
                        tz=tz,
                        freq='D')

    result = dti.snap(freq='W-MON')
    expected = date_range('12/31/2001',
                          '1/7/2002',
                          name=name,
                          tz=tz,
                          freq='w-mon')
    expected = expected.repeat([3, 4])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz

    result = dti.snap(freq='B')

    expected = date_range('1/1/2002', '1/7/2002', name=name, tz=tz, freq='b')
    expected = expected.repeat([1, 1, 1, 2, 2])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz
Beispiel #2
0
def test_dti_snap(name, tz):
    dti = DatetimeIndex(
        [
            "1/1/2002",
            "1/2/2002",
            "1/3/2002",
            "1/4/2002",
            "1/5/2002",
            "1/6/2002",
            "1/7/2002",
        ],
        name=name,
        tz=tz,
        freq="D",
    )

    result = dti.snap(freq="W-MON")
    expected = date_range("12/31/2001",
                          "1/7/2002",
                          name=name,
                          tz=tz,
                          freq="w-mon")
    expected = expected.repeat([3, 4])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz

    result = dti.snap(freq="B")

    expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
    expected = expected.repeat([1, 1, 1, 2, 2])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz
Beispiel #3
0
def test_dti_snap():
    dti = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
                         '1/5/2002', '1/6/2002', '1/7/2002'], freq='D')

    res = dti.snap(freq='W-MON')
    exp = date_range('12/31/2001', '1/7/2002', freq='w-mon')
    exp = exp.repeat([3, 4])
    assert (res == exp).all()

    res = dti.snap(freq='B')

    exp = date_range('1/1/2002', '1/7/2002', freq='b')
    exp = exp.repeat([1, 1, 1, 2, 2])
    assert (res == exp).all()
Beispiel #4
0
def test_dti_snap():
    dti = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
                         '1/5/2002', '1/6/2002', '1/7/2002'], freq='D')

    res = dti.snap(freq='W-MON')
    exp = date_range('12/31/2001', '1/7/2002', freq='w-mon')
    exp = exp.repeat([3, 4])
    assert (res == exp).all()

    res = dti.snap(freq='B')

    exp = date_range('1/1/2002', '1/7/2002', freq='b')
    exp = exp.repeat([1, 1, 1, 2, 2])
    assert (res == exp).all()
Beispiel #5
0
    def test_dti_snap(self):
        dti = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
                             '1/5/2002', '1/6/2002', '1/7/2002'], freq='D')

        res = dti.snap(freq='W-MON')

        exp = DatetimeIndex(['12/31/2001', '12/31/2001', '12/31/2001',
                             '1/7/2002', '1/7/2002', '1/7/2002', '1/7/2002'],
                             freq='W-MON')

        self.assert_( (res == exp).all() )

        res = dti.snap(freq='B')

        exp = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
                             '1/4/2002', '1/7/2002', '1/7/2002'], freq='B')

        self.assert_( (res == exp).all() )
Beispiel #6
0
def test_dti_snap(name, tz):
    dti = DatetimeIndex(['1/1/2002', '1/2/2002', '1/3/2002', '1/4/2002',
                         '1/5/2002', '1/6/2002', '1/7/2002'],
                        name=name, tz=tz, freq='D')

    result = dti.snap(freq='W-MON')
    expected = date_range('12/31/2001', '1/7/2002',
                          name=name, tz=tz, freq='w-mon')
    expected = expected.repeat([3, 4])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz

    result = dti.snap(freq='B')

    expected = date_range('1/1/2002', '1/7/2002',
                          name=name, tz=tz, freq='b')
    expected = expected.repeat([1, 1, 1, 2, 2])
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz
Beispiel #7
0
    def test_dti_snap(self):
        dti = DatetimeIndex(
            ["1/1/2002", "1/2/2002", "1/3/2002", "1/4/2002", "1/5/2002", "1/6/2002", "1/7/2002"], freq="D"
        )

        res = dti.snap(freq="W-MON")

        exp = DatetimeIndex(
            ["12/31/2001", "12/31/2001", "12/31/2001", "1/7/2002", "1/7/2002", "1/7/2002", "1/7/2002"], freq="W-MON"
        )

        self.assert_((res == exp).all())

        res = dti.snap(freq="B")

        exp = DatetimeIndex(
            ["1/1/2002", "1/2/2002", "1/3/2002", "1/4/2002", "1/4/2002", "1/7/2002", "1/7/2002"], freq="B"
        )

        self.assert_((res == exp).all())
Beispiel #8
0
def test_dti_snap(name, tz, unit):
    dti = DatetimeIndex(
        [
            "1/1/2002",
            "1/2/2002",
            "1/3/2002",
            "1/4/2002",
            "1/5/2002",
            "1/6/2002",
            "1/7/2002",
        ],
        name=name,
        tz=tz,
        freq="D",
    )
    dti = astype_non_nano(dti, unit)

    result = dti.snap(freq="W-MON")
    expected = date_range("12/31/2001",
                          "1/7/2002",
                          name=name,
                          tz=tz,
                          freq="w-mon")
    expected = expected.repeat([3, 4])
    expected = astype_non_nano(expected, unit)
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz
    assert result.freq is None
    assert expected.freq is None

    result = dti.snap(freq="B")

    expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
    expected = expected.repeat([1, 1, 1, 2, 2])
    expected = astype_non_nano(expected, unit)
    tm.assert_index_equal(result, expected)
    assert result.tz == expected.tz
    assert result.freq is None
    assert expected.freq is None