Beispiel #1
0
def test_get_pivots_by_invalid_unit():
    with pytest.raises(ValueError,
                       match=r".*invalid_unit.*is not supported.*"):
        pivots = get_pivots(observations=[],
                            pivot_interval=1,
                            start_date=2015.0,
                            end_date=2016.0,
                            pivot_interval_units="invalid_unit")
Beispiel #2
0
def test_get_pivots_by_weeks():
    """Get pivots where intervals are defined as weeks instead of months.
    """
    pivots = get_pivots(observations=[],
                        pivot_interval=1,
                        start_date=2015.0,
                        end_date=2016.0,
                        pivot_interval_units="weeks")
    assert len(pivots) == 52
Beispiel #3
0
def test_get_pivots_from_tree_only(tree):
    """Test pivot calculations.
    """
    # Define pivot frequency in months.
    pivot_frequency = 3
    observations = [tip.attr["num_date"] for tip in tree.get_terminals()]
    pivots = get_pivots(observations, pivot_frequency)
    assert isinstance(pivots, np.ndarray)

    # Floating point pivot values should be separated by the given number of
    # months divided by number of months in a year.
    assert pivots[1] - pivots[0] == pivot_frequency / 12.0
def test_get_pivots_from_tree_only(tree):
    """Test pivot calculations.
    """
    # Define pivot frequency in months.
    pivot_frequency = 3
    observations = [tip.attr["num_date"] for tip in tree.get_terminals()]
    pivots = get_pivots(observations, pivot_frequency)
    assert isinstance(pivots, np.ndarray)

    # Floating point pivot values should be separated by the given number of
    # months divided by number of months in a year.
    assert pivots[1] - pivots[0] == pivot_frequency / 12.0
Beispiel #5
0
def test_get_pivots_by_months():
    """Get pivots where intervals are defined by months.
    """
    pivots = get_pivots(observations=[],
                        pivot_interval=1,
                        start_date=2015.0,
                        end_date=2016.0,
                        pivot_interval_units="months")
    # Pivots should include all 12 months of the year plus the month represented
    # by the end date, since the pandas month interval uses "month starts". See
    # pandas date offsets documentation for more details:
    # https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
    assert len(pivots) == 13
def test_get_pivots_from_start_and_end_date():
    """
    Test pivot calculation from a given start and end date instead of a given tree.
    """
    pivot_frequency = 3
    start_date = 2015.5
    end_date = 2018.5
    observations = []
    pivots = get_pivots(observations, pivot_frequency, start_date=start_date, end_date=end_date)
    assert isinstance(pivots, np.ndarray)
    assert pivots[1] - pivots[0] == pivot_frequency / 12.0
    assert pivots[0] == start_date
    assert pivots[-1] == end_date
    assert pivots[-1] >= end_date - pivot_frequency
Beispiel #7
0
def test_get_pivots_from_start_and_end_date():
    """
    Test pivot calculation from a given start and end date instead of a given tree.
    """
    pivot_frequency = 3
    start_date = 2015.5
    end_date = 2018.5
    observations = []
    pivots = get_pivots(observations,
                        pivot_frequency,
                        start_date=start_date,
                        end_date=end_date)
    assert isinstance(pivots, np.ndarray)
    assert pivots[1] - pivots[0] == pivot_frequency / 12.0
    assert pivots[0] == start_date
    assert pivots[-1] == end_date
    assert pivots[-1] >= end_date - pivot_frequency
Beispiel #8
0
def test_get_pivots_from_start_and_end_date():
    """
    Test pivot calculation from a given start and end date instead of a given tree
    First pivot is the first day of the month immediately following start_date
    Last pivot is the first day of the month immediately preceding end_date
    Current logic converts numeric date 2015.5 to 2015-07-02, hence using 2015.49
    """
    pivot_frequency = 1
    start_date = 2015.49
    end_date = 2018.5
    observations = []
    pivots = get_pivots(observations,
                        pivot_frequency,
                        start_date=start_date,
                        end_date=end_date)
    assert isinstance(pivots, np.ndarray)
    assert np.round(12 * (pivots[1] - pivots[0])) == pivot_frequency
    assert pivots[0] == 2015.5
    assert pivots[-1] == 2018.5
    assert pivots[-1] >= end_date - pivot_frequency