Skip to content
Snippets Groups Projects

Periodic mask fix

Merged Peter Lünenschloß requested to merge periodicMaskFix into develop

MR adresses:

#332 (closed) : mask swap upon include_bouds=True is fixed

#322 (closed) : maskTime actually performs a selection and should be named accordingly (selectTime)

Some minor cleanups in the documentation of selectTime (reference to false/non-existing parameters)

closes #332 (closed) #322 (closed)

Edited by Bert Palm

Merge request reports

Pipeline #83274 passed

Pipeline passed for 652a183f on periodicMaskFix

Test coverage 74.00% (0.00%) from 1 job
Approved by

Merged by Peter LünenschloßPeter Lünenschloß 3 years ago (Apr 4, 2022 10:57am UTC)

Pipeline #83498 passed

Pipeline passed for 0fd879c6 on develop

Test coverage 74.00% (0.00%) from 1 job

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Peter Lünenschloß changed milestone to %2.1.0

    changed milestone to %2.1.0

  • Peter Lünenschloß requested review from @palmb

    requested review from @palmb

  • added 1 commit

    Compare with previous version

  • Bert Palm changed the description

    changed the description

  • Bert Palm added 1 commit

    added 1 commit

    Compare with previous version

  • unfortunately the test in tests/lib does not run automatically.. so you should call tyhe testsuite local

  • added 2 commits

    • 8d9b24d9 - fixed error appearing when ring to mask empty seasons
    • aaee17b5 - fixed masking tests (swapped True and False)

    Compare with previous version

  • added 1 commit

    • 5cb706e2 - added reuse compliance to test periodic mask

    Compare with previous version

  • removed python label

  • this is the current test output..

    =========================== short test summary info ============================
    FAILED test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-True-exp0-index0]
    FAILED test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-False-exp1-index0]
    FAILED test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-True-exp2-index0]
    FAILED test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-False-exp3-index0]
    ========================= 4 failed, 2 passed in 1.88s ==========================
    
    Expand all
    /home/palmb/.virtualenvs/saqc3.9/bin/python /snap/pycharm-professional/278/plugins/python/helpers/pycharm/_jb_pytest_runner.py --path /home/palmb/projects/saqc/tests/lib/test_periodicMask.py -- --jb-show-summary
    Testing started at 11:20 ...
    Launching pytest with arguments /home/palmb/projects/saqc/tests/lib/test_periodicMask.py in /home/palmb/projects/saqc/tests/lib
    
    ============================= test session starts ==============================
    platform linux -- Python 3.9.5, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /home/palmb/.virtualenvs/saqc3.9/bin/python
    cachedir: .pytest_cache
    hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/palmb/projects/saqc/tests/lib/.hypothesis/examples')
    rootdir: /home/palmb/projects/saqc
    plugins: hypothesis-6.17.4, lazy-fixture-0.6.3
    collecting ... collected 6 items
    
    test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-True-exp0-index0] FAILED [ 16%]
                 result    exp
    1999-10-01    True   True
    1999-11-01    True   True
    1999-12-01    True   True
    2000-01-01   False  False
    2000-02-01    True  False
    2000-03-01    True  False
    
    tests/lib/test_periodicMask.py:26 (test_bounds[01-01T00:00:00-01-03T00:00:00-True-exp0-index0])
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-01T00:00:00', end = '01-03T00:00:00', closed = True
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool>(1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool> = 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    FAILED [ 33%]
                 result    exp
    1999-10-01    True   True
    1999-11-01    True   True
    1999-12-01    True   True
    2000-01-01    True   True
    2000-02-01    True  False
    2000-03-01    True   True
    
    tests/lib/test_periodicMask.py:26 (test_bounds[01-01T00:00:00-01-03T00:00:00-False-exp1-index0])
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-01T00:00:00', end = '01-03T00:00:00', closed = False
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01     True
    2000-02-01    False
    2000-03-01     True
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    True
    1999-11-01    True
    1999-12-01    True
    2000-01-01    True
    2000-02-01    True
    2000-03-01    True
    dtype: bool
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01     True
    2000-02-01    False
    2000-03-01     True
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool>(1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01     True\n2000-02-01    False\n2000-03-01     True\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool> = 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    FAILED [ 50%]
                 result    exp
    1999-10-01   False  False
    1999-11-01   False  False
    1999-12-01   False  False
    2000-01-01   False  False
    2000-02-01   False   True
    2000-03-01   False  False
    
    tests/lib/test_periodicMask.py:26 (test_bounds[01-03T00:00:00-01-01T00:00:00-True-exp2-index0])
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-03T00:00:00', end = '01-01T00:00:00', closed = True
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01     True
    2000-03-01    False
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01     True
    2000-03-01    False
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool>(1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01     True\n2000-03-01    False\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool> = 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    FAILED [ 66%]
                 result    exp
    1999-10-01   False  False
    1999-11-01   False  False
    1999-12-01   False  False
    2000-01-01    True   True
    2000-02-01   False   True
    2000-03-01   False   True
    
    tests/lib/test_periodicMask.py:26 (test_bounds[01-03T00:00:00-01-01T00:00:00-False-exp3-index0])
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-03T00:00:00', end = '01-01T00:00:00', closed = False
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool>(1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01     True\n2000-03-01     True\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool> = 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    
    
    
    
    
    PASSED [ 83%]PASSED [100%]
    
    
    
    
    
    
    
    
    
    
    test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-False-exp1-index0] 
    test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-True-exp2-index0] 
    test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-False-exp3-index0] 
    test_periodicMask.py::test_season[01-01T00:00:00-03-01T00:00:00-True-exp0-index0] 
    test_periodicMask.py::test_season[01-01T00:00:00-03-01T00:00:00-False-exp1-index0] 
    
    =================================== FAILURES ===================================
    _________ test_bounds[01-01T00:00:00-01-03T00:00:00-True-exp0-index0] __________
    
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-01T00:00:00', end = '01-03T00:00:00', closed = True
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool>(1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool> = 1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01    False\n2000-02-01     True\n2000-03-01     True\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    ----------------------------- Captured stdout call -----------------------------
    
                 result    exp
    1999-10-01    True   True
    1999-11-01    True   True
    1999-12-01    True   True
    2000-01-01   False  False
    2000-02-01    True  False
    2000-03-01    True  False
    _________ test_bounds[01-01T00:00:00-01-03T00:00:00-False-exp1-index0] _________
    
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-01T00:00:00', end = '01-03T00:00:00', closed = False
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01     True
    2000-02-01    False
    2000-03-01     True
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    True
    1999-11-01    True
    1999-12-01    True
    2000-01-01    True
    2000-02-01    True
    2000-03-01    True
    dtype: bool
    exp = 1999-10-01     True
    1999-11-01     True
    1999-12-01     True
    2000-01-01     True
    2000-02-01    False
    2000-03-01     True
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool>(1999-10-01     True\n1999-11-01     True\n1999-12-01     True\n2000-01-01     True\n2000-02-01    False\n2000-03-01     True\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool> = 1999-10-01    True\n1999-11-01    True\n1999-12-01    True\n2000-01-01    True\n2000-02-01    True\n2000-03-01    True\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    ----------------------------- Captured stdout call -----------------------------
    
                 result    exp
    1999-10-01    True   True
    1999-11-01    True   True
    1999-12-01    True   True
    2000-01-01    True   True
    2000-02-01    True  False
    2000-03-01    True   True
    _________ test_bounds[01-03T00:00:00-01-01T00:00:00-True-exp2-index0] __________
    
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-03T00:00:00', end = '01-01T00:00:00', closed = True
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01     True
    2000-03-01    False
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01    False
    2000-02-01     True
    2000-03-01    False
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool>(1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01     True\n2000-03-01    False\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool> = 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01    False\n2000-02-01    False\n2000-03-01    False\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    ----------------------------- Captured stdout call -----------------------------
    
                 result    exp
    1999-10-01   False  False
    1999-11-01   False  False
    1999-12-01   False  False
    2000-01-01   False  False
    2000-02-01   False   True
    2000-03-01   False  False
    _________ test_bounds[01-03T00:00:00-01-01T00:00:00-False-exp3-index0] _________
    
    index = DatetimeIndex(['1999-10-01', '1999-11-01', '1999-12-01', '2000-01-01',
                   '2000-02-01', '2000-03-01'],
                  dtype='datetime64[ns]', freq=None)
    start = '01-03T00:00:00', end = '01-01T00:00:00', closed = False
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    
        @pytest.mark.parametrize(
            "index",
            [
                pd.DatetimeIndex(
                    [
                        "1999-10",
                        "1999-11",
                        "1999-12",
                        "2000-01",
                        "2000-02",
                        "2000-03",
                    ]
                )
            ],
        )
        @pytest.mark.parametrize(
            "start, end, closed, exp",
            [
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    True,
                    [unmasked, unmasked, unmasked, masked, masked, masked],
                ),
                (
                    "01-01T00:00:00",
                    "01-03T00:00:00",
                    False,
                    [unmasked, unmasked, unmasked, unmasked, masked, unmasked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    True,
                    [masked, masked, masked, masked, unmasked, masked],
                ),
                (
                    "01-03T00:00:00",
                    "01-01T00:00:00",
                    False,
                    [masked, masked, masked, unmasked, unmasked, unmasked],
                ),
            ],
        )
        def test_bounds(index, start, end, closed, exp):
            exp = pd.Series(exp, index=index, dtype=bool)
            result = periodicMask(index, start, end, closed)
    >       assert_equal(result, exp)
    
    test_periodicMask.py:74: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    result = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01    False
    2000-03-01    False
    dtype: bool
    exp = 1999-10-01    False
    1999-11-01    False
    1999-12-01    False
    2000-01-01     True
    2000-02-01     True
    2000-03-01     True
    dtype: bool
    
        def assert_equal(result, exp):
            assert exp.index.equals(result.index)
            assert result.dtype == exp.dtype
        
            if result.equals(exp):
                return
        
            df = pd.DataFrame(
                data=np.array([result, exp]).T, index=exp.index, columns=["result", "exp"]
            )
            print("\n", df)
    >       assert result.equals(exp)
    E       assert False
    E        +  where False = <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool>(1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01     True\n2000-03-01     True\ndtype: bool)
    E        +    where <bound method NDFrame.equals of 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool> = 1999-10-01    False\n1999-11-01    False\n1999-12-01    False\n2000-01-01     True\n2000-02-01    False\n2000-03-01    False\ndtype: bool.equals
    
    test_periodicMask.py:24: AssertionError
    ----------------------------- Captured stdout call -----------------------------
    
                 result    exp
    1999-10-01   False  False
    1999-11-01   False  False
    1999-12-01   False  False
    2000-01-01    True   True
    2000-02-01   False   True
    2000-03-01   False   True
    =========================== short test summary info ============================
    FAILED test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-True-exp0-index0]
    FAILED test_periodicMask.py::test_bounds[01-01T00:00:00-01-03T00:00:00-False-exp1-index0]
    FAILED test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-True-exp2-index0]
    FAILED test_periodicMask.py::test_bounds[01-03T00:00:00-01-01T00:00:00-False-exp3-index0]
    ========================= 4 failed, 2 passed in 1.88s ==========================
    
    Process finished with exit code 1
    
    
    
    
    
    
    
    Edited by Bert Palm
  • added 1 commit

    Compare with previous version

  • mentioned in commit 0fd879c6

  • David Schäfer mentioned in commit 63b55c6d

    mentioned in commit 63b55c6d

  • David Schäfer mentioned in commit 684dc8a0

    mentioned in commit 684dc8a0

  • David Schäfer mentioned in commit 8f7a90e4

    mentioned in commit 8f7a90e4

Please register or sign in to reply
Loading