コード例 #1
0
def test_resample_smry_dates():
    """Test resampling of summary dates"""

    eclfiles = EclFiles(DATAFILE)

    ecldates = eclfiles.get_eclsum().dates

    assert isinstance(resample_smry_dates(ecldates), list)
    assert isinstance(resample_smry_dates(ecldates, freq="last"), list)
    assert isinstance(
        resample_smry_dates(ecldates, freq="last")[0], datetime.date)

    monthly = resample_smry_dates(ecldates, freq="monthly")
    assert monthly[-1] > monthly[0]  # end date is later than start
    assert len(resample_smry_dates(ecldates, freq="yearly")) == 5
    assert len(monthly) == 38
    assert len(resample_smry_dates(ecldates, freq="daily")) == 1098

    weekly = resample_smry_dates(ecldates, freq="weekly")
    assert len(weekly) == 159

    assert resample_smry_dates(ecldates,
                               freq="2001-04-05") == [dt(2001, 4, 5, 0, 0)]
    assert resample_smry_dates(ecldates, freq=datetime.date(
        2001, 4, 5)) == [datetime.date(2001, 4, 5)]
    assert resample_smry_dates(ecldates, freq=dt(2001, 4, 5, 0,
                                                 0)) == [dt(2001, 4, 5, 0, 0)]
    # start and end should be included:
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-06-05",
                            end_date="2000-06-07",
                            freq="daily")) == 3)
    # No month boundary between start and end, but we
    # should have the starts and ends included
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-06-05",
                            end_date="2000-06-07",
                            freq="monthly")) == 2)
    # Date normalization should be overriden here:
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="monthly",
            normalize=True,
        )) == 2)
    # Start_date and end_date at the same date should work
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-01-01",
                            end_date="2000-01-01")) == 1)
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-01-01",
                            end_date="2000-01-01",
                            normalize=True)) == 1)

    # Check that we can go way outside the smry daterange:
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="1978-01-01",
                            end_date="2030-01-01",
                            freq="yearly")) == 53)
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="1978-01-01",
            end_date="2030-01-01",
            freq="yearly",
            normalize=True,
        )) == 53)

    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="raw",
            normalize=True,
        )) == 2)
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="raw",
            normalize=False,
        )) == 2)

    # Check that we can be outside the nanosecond timestamp limitation in Pandas:
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2300-06-07",
            freq="yearly",
            normalize=True,
        )) == 2 + 300  # boundary dates + 2001-01-01 to 2300-01-01
            )

    # Verify boundary date bug up to and including ecl2df v0.13.2
    assert (resample_smry_dates(
        ecldates,
        start_date="2300-06-05",
        end_date="2301-06-07",
        freq="yearly",
        normalize=False,
    ) == [dt(2300, 6, 5).date(),
          dt(2301, 1, 1).date(),
          dt(2301, 6, 7).date()])
    # Normalization should not change anything when dates are explicit:
    assert (resample_smry_dates(
        ecldates,
        start_date="2300-06-05",
        end_date="2301-06-07",
        freq="yearly",
        normalize=True,
    ) == [dt(2300, 6, 5).date(),
          dt(2301, 1, 1).date(),
          dt(2301, 6, 7).date()])
コード例 #2
0
def test_resample_smry_dates():
    """Test resampling of summary dates"""

    eclfiles = EclFiles(DATAFILE)

    ecldates = eclfiles.get_eclsum().dates

    assert isinstance(resample_smry_dates(ecldates), list)
    assert isinstance(resample_smry_dates(ecldates, freq="last"), list)
    assert isinstance(
        resample_smry_dates(ecldates, freq="last")[0], datetime.date)

    monthly = resample_smry_dates(ecldates, freq="monthly")
    assert monthly[-1] > monthly[0]  # end date is later than start
    assert len(resample_smry_dates(ecldates, freq="yearly")) == 5
    assert len(monthly) == 38
    assert len(resample_smry_dates(ecldates, freq="daily")) == 1098

    # start and end should be included:
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-06-05",
                            end_date="2000-06-07",
                            freq="daily")) == 3)
    # No month boundary between start and end, but we
    # should have the starts and ends included
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-06-05",
                            end_date="2000-06-07",
                            freq="monthly")) == 2)
    # Date normalization should be overriden here:
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="monthly",
            normalize=True,
        )) == 2)
    # Start_date and end_date at the same date should work
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-01-01",
                            end_date="2000-01-01")) == 1)
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="2000-01-01",
                            end_date="2000-01-01",
                            normalize=True)) == 1)

    # Check that we can go way outside the smry daterange:
    assert (len(
        resample_smry_dates(ecldates,
                            start_date="1978-01-01",
                            end_date="2030-01-01",
                            freq="yearly")) == 53)
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="1978-01-01",
            end_date="2030-01-01",
            freq="yearly",
            normalize=True,
        )) == 53)

    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="raw",
            normalize=True,
        )) == 2)
    assert (len(
        resample_smry_dates(
            ecldates,
            start_date="2000-06-05",
            end_date="2000-06-07",
            freq="raw",
            normalize=False,
        )) == 2)