Skip to content

Commit

Permalink
added test-cases with tz
Browse files Browse the repository at this point in the history
  • Loading branch information
Alina Voilova committed Feb 9, 2024
1 parent 091c67f commit 1c327b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
39 changes: 27 additions & 12 deletions tests/core/pfline/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@


@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize("slice_start", ["2021", "2022", "2022-01-02"])
@pytest.mark.parametrize(
"slice_start", ["2021", "2022", "2022-01-02", "2022-05-23 14:34"]
)
@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
def test_flat_slice_start(slice_start: str, freq: str, tz: str):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_flatpfline(index)
assert pfl1.slice[slice_start:] == pfl1.loc[slice_start:]


@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize(
"slice_end",
Expand All @@ -25,8 +28,8 @@ def test_flat_slice_start(slice_start: str, freq: str, tz: str):
("2022-01-02", "2022-01-01"),
],
)
def test_flat_slice_end(slice_end, freq):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
def test_flat_slice_end(slice_end: str, freq: str, tz: str):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_flatpfline(index)
assert pfl1.slice[: slice_end[0]] == pfl1.loc[: slice_end[1]]

Expand All @@ -36,11 +39,12 @@ def test_flat_slice_end(slice_end, freq):
"where",
["2022", "2022-03", "2022-04-21", "2022-05-23 14:34"],
)
def test_flat_slice_whole(where: str, freq: str):
@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
def test_flat_slice_whole(where: str, freq: str, tz: str):
"""Test that slicing splits the pfl in 2 non-overlapping pieces without gap
(i.e., ensure that each original timestamp is in exactly one of the resulting pieces.)
"""
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_flatpfline(index)
left, right = pfl1.slice[:where], pfl1.slice[where:]
# Test that each timestamp is present at least once.
Expand All @@ -50,14 +54,24 @@ def test_flat_slice_whole(where: str, freq: str):


@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize("slice_start", ["2021", "2022", "2022-01-02"])
def test_nested_slice_start(slice_start, freq):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
@pytest.mark.parametrize(
"slice_start",
[
"2021",
"2022",
"2022-01-02",
"2022-01-02 14:30",
],
)
@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
def test_nested_slice_start(slice_start: str, freq: str, tz: str):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_nestedpfline(index)
assert pfl1.slice[slice_start:] == pfl1.loc[slice_start:]


@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
@pytest.mark.parametrize(
"slice_end",
[
Expand All @@ -68,22 +82,23 @@ def test_nested_slice_start(slice_start, freq):
("2022-01-02", "2022-01-01"),
],
)
def test_nested_slice_end(slice_end, freq):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
def test_nested_slice_end(slice_end: str, freq: str, tz: str):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_nestedpfline(index)
assert pfl1.slice[: slice_end[0]] == pfl1.loc[: slice_end[1]]


@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize("tz", [None, "Europe/Berlin"])
@pytest.mark.parametrize(
"where",
["2022", "2022-03", "2022-04-21", "2022-05-23 14:34"],
)
def test_nested_slice_whole(where: str, freq: str):
def test_nested_slice_whole(where: str, freq: str, tz: str):
"""Test that slicing splits the pfl in 2 non-overlapping pieces without gap
(i.e., ensure that each original timestamp is in exactly one of the resulting pieces.)
"""
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
index = pd.date_range("2020", "2024", freq=freq, inclusive="left", tz=tz)
pfl1 = dev.get_nestedpfline(index)
left, right = pfl1.slice[:where], pfl1.slice[where:]
# Test that each timestamp is present at least once.
Expand Down
10 changes: 9 additions & 1 deletion tests/core/pfstate/test_slice_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ def test_slice_state(slice_start, slice_end, freq):


@pytest.mark.parametrize("freq", ["MS", "AS", "QS", "D", "15T"])
@pytest.mark.parametrize("slice_start", ["2021", "2022", "2022-01-02"])
@pytest.mark.parametrize(
"slice_start",
[
"2021",
"2022",
"2022-01-02",
"2022-01-02 14:00",
],
)
def test_state_slice_start(slice_start, freq):
index = pd.date_range("2020", "2024", freq=freq, inclusive="left")
pfs = dev.get_pfstate(index)
Expand Down

0 comments on commit 1c327b2

Please sign in to comment.