From 88a8549157ac64c55fe77a9c76a5cee581f75e37 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Sun, 5 May 2024 20:46:40 +0200 Subject: [PATCH 1/9] Add constructor for sequence sets using instants with gaps --- pymeos/temporal/tsequenceset.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pymeos/temporal/tsequenceset.py b/pymeos/temporal/tsequenceset.py index b9213130..3d407a99 100644 --- a/pymeos/temporal/tsequenceset.py +++ b/pymeos/temporal/tsequenceset.py @@ -1,16 +1,16 @@ from __future__ import annotations from abc import ABC +from datetime import timedelta from typing import Optional, List, Union, Any, TypeVar, Type, TYPE_CHECKING from pymeos_cffi import * -from .temporal import Temporal, import_pandas +from .temporal import Temporal, import_pandas, TInterpolation if TYPE_CHECKING: import pandas as pd - TBase = TypeVar("TBase") TG = TypeVar("TG", bound="Temporal[Any]") TI = TypeVar("TI", bound="TInstant[Any]") @@ -71,6 +71,22 @@ def from_sequences( """ return cls(sequence_list=sequence_list, normalize=normalize) + @classmethod + def from_instants_with_gaps( + cls, + instants: list[TI], + interpolation: TInterpolation, + max_time: timedelta = None, + max_distance: float = 0.0, + ): + instant_inners = [x._inner for x in instants] + interval = timedelta_to_interval(max_time) if max_time is not None else None + return cls( + _inner=tsequenceset_make_gaps( + instant_inners, interpolation, interval, max_distance + ) + ) + # ------------------------- Accessors ------------------------------------- def num_sequences(self) -> int: """ From 0a6c814ed4f775446bf43bf6281089e1e706c402 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Sun, 5 May 2024 22:05:15 +0200 Subject: [PATCH 2/9] Add tests for TBoolSeqSet --- tests/main/tbool_test.py | 989 ++++++++++++++++++++------------------- 1 file changed, 517 insertions(+), 472 deletions(-) diff --git a/tests/main/tbool_test.py b/tests/main/tbool_test.py index 908a3348..3b13ef1f 100644 --- a/tests/main/tbool_test.py +++ b/tests/main/tbool_test.py @@ -16,6 +16,7 @@ TsTzSpan, TsTzSpanSet, ) +from pymeos_cffi import MeosException from tests.conftest import TestPyMEOS @@ -36,21 +37,21 @@ class TestTBoolConstructors(TestTBool): [ (TIntInst("1@2019-09-01"), TBoolInst, TInterpolation.NONE), ( - TIntSeq("{1@2019-09-01, 0@2019-09-02}"), - TBoolSeq, - TInterpolation.DISCRETE, + TIntSeq("{1@2019-09-01, 0@2019-09-02}"), + TBoolSeq, + TInterpolation.DISCRETE, ), ( - TIntSeq("[1@2019-09-01, 0@2019-09-02]"), - TBoolSeq, - TInterpolation.STEPWISE, + TIntSeq("[1@2019-09-01, 0@2019-09-02]"), + TBoolSeq, + TInterpolation.STEPWISE, ), ( - TIntSeqSet( - "{[1@2019-09-01, 0@2019-09-02],[1@2019-09-03, 1@2019-09-05]}" - ), - TBoolSeqSet, - TInterpolation.STEPWISE, + TIntSeqSet( + "{[1@2019-09-01, 0@2019-09-02],[1@2019-09-03, 1@2019-09-05]}" + ), + TBoolSeqSet, + TInterpolation.STEPWISE, ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -65,15 +66,15 @@ def test_from_base_constructor(self, source, type, interpolation): [ (datetime(2000, 1, 1), TBoolInst, TInterpolation.NONE), ( - TsTzSet("{2019-09-01, 2019-09-02}"), - TBoolSeq, - TInterpolation.DISCRETE, + TsTzSet("{2019-09-01, 2019-09-02}"), + TBoolSeq, + TInterpolation.DISCRETE, ), (TsTzSpan("[2019-09-01, 2019-09-02]"), TBoolSeq, TInterpolation.STEPWISE), ( - TsTzSpanSet("{[2019-09-01, 2019-09-02],[2019-09-03, 2019-09-05]}"), - TBoolSeqSet, - TInterpolation.STEPWISE, + TsTzSpanSet("{[2019-09-01, 2019-09-02],[2019-09-03, 2019-09-05]}"), + TBoolSeqSet, + TInterpolation.STEPWISE, ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -87,29 +88,29 @@ def test_from_base_time_constructor(self, source, type, interpolation): "source, type, interpolation, expected", [ ( - "True@2019-09-01", - TBoolInst, - TInterpolation.NONE, - "t@2019-09-01 00:00:00+00", + "True@2019-09-01", + TBoolInst, + TInterpolation.NONE, + "t@2019-09-01 00:00:00+00", ), ( - "{True@2019-09-01, False@2019-09-02}", - TBoolSeq, - TInterpolation.DISCRETE, - "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}", + "{True@2019-09-01, False@2019-09-02}", + TBoolSeq, + TInterpolation.DISCRETE, + "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}", ), ( - "[True@2019-09-01, False@2019-09-02]", - TBoolSeq, - TInterpolation.STEPWISE, - "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]", + "[True@2019-09-01, False@2019-09-02]", + TBoolSeq, + TInterpolation.STEPWISE, + "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]", ), ( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}", - TBoolSeqSet, - TInterpolation.STEPWISE, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}", + TBoolSeqSet, + TInterpolation.STEPWISE, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -124,16 +125,16 @@ def test_string_constructor(self, source, type, interpolation, expected): "source, type, expected", [ ( - "[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]", - TBoolSeq, - "[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00]", + "[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]", + TBoolSeq, + "[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00]", ), ( - "{[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]," - "[True@2019-09-07, True@2019-09-08, True@2019-09-09]}", - TBoolSeqSet, - "{[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00], " - "[t@2019-09-07 00:00:00+00, t@2019-09-09 00:00:00+00]}", + "{[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]," + "[True@2019-09-07, True@2019-09-08, True@2019-09-09]}", + TBoolSeqSet, + "{[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00], " + "[t@2019-09-07 00:00:00+00, t@2019-09-09 00:00:00+00]}", ), ], ids=["Sequence", "SequenceSet"], @@ -161,62 +162,62 @@ def test_value_timestamp_instant_constructor(self, value, timestamp): "list, interpolation, normalize, expected", [ ( - ["True@2019-09-01", "False@2019-09-03"], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + ["True@2019-09-01", "False@2019-09-03"], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - ["True@2019-09-01", "False@2019-09-03"], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "False@2019-09-03"], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", TBoolInst("False@2019-09-03")], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + ["True@2019-09-01", TBoolInst("False@2019-09-03")], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - ["True@2019-09-01", TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", "True@2019-09-02", "False@2019-09-03"], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "True@2019-09-02", "False@2019-09-03"], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - [ - TBoolInst("True@2019-09-01"), - TBoolInst("True@2019-09-02"), - TBoolInst("False@2019-09-03"), - ], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + [ + TBoolInst("True@2019-09-01"), + TBoolInst("True@2019-09-02"), + TBoolInst("False@2019-09-03"), + ], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", "True@2019-09-02", TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "True@2019-09-02", TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ], ids=[ @@ -232,7 +233,7 @@ def test_value_timestamp_instant_constructor(self, value, timestamp): ], ) def test_instant_list_sequence_constructor( - self, list, interpolation, normalize, expected + self, list, interpolation, normalize, expected ): tbs = TBoolSeq( instant_list=list, @@ -249,6 +250,50 @@ def test_instant_list_sequence_constructor( assert str(tbs2) == expected assert tbs2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TBoolInst("True@2000-01-01"), + TBoolInst("False@2000-01-02"), + TBoolInst("False@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TBoolSeqSet("{[True@2000-01-01, False@2000-01-02, False@2000-01-05]}"), + ), + ( + ( + [ + TBoolInst("True@2000-01-01"), + TBoolInst("False@2000-01-02"), + TBoolInst("False@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TBoolSeqSet("{[True@2000-01-01, False@2000-01-02], [False@2000-01-05]}"), + ) + ], + ids=["No Gaps", "With Gaps"], + ) + def test_gaps_constructor(self, params, result): + assert TBoolSeqSet.from_instants_with_gaps(*params) == result + + def test_gaps_constructor_with_distance_raises(self): + instants = [ + TBoolInst(value=True, timestamp="2000-01-01"), + TBoolInst(value=False, timestamp="2000-01-02"), + TBoolInst(value=False, timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TBoolSeqSet.from_instants_with_gaps( + instants, TInterpolation.STEPWISE, max_distance=2 + ) + @pytest.mark.parametrize( "temporal", [tbi, tbds, tbs, tbss], @@ -286,9 +331,9 @@ class TestTBoolOutputs(TestTBool): (tbds, "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}"), (tbs, "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]"), ( - tbss, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + tbss, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -303,9 +348,9 @@ def test_str(self, temporal, expected): (tbds, "TBoolSeq({t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00})"), (tbs, "TBoolSeq([t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00])"), ( - tbss, - "TBoolSeqSet({[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]})", + tbss, + "TBoolSeqSet({[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]})", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -320,9 +365,9 @@ def test_repr(self, temporal, expected): (tbds, "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}"), (tbs, "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]"), ( - tbss, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + tbss, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -337,9 +382,9 @@ def test_as_wkt(self, temporal, expected): (tbds, "0114000602000000030100A01E4E71340200000000F66B85340200"), (tbs, "0114000A02000000030100A01E4E71340200000000F66B85340200"), ( - tbss, - "0114000B0200000002000000030100A01E4E71340200000000F" - "66B853402000200000003010060CD89993402000100207CC5C1340200", + tbss, + "0114000B0200000002000000030100A01E4E71340200000000F" + "66B853402000200000003010060CD89993402000100207CC5C1340200", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -351,108 +396,108 @@ def test_as_hexwkb(self, temporal, expected): "temporal, expected", [ ( - tbi, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-01T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00"\n' - " ],\n" - ' "interpolation": "None"\n' - "}", - ), - ( - tbds, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-02T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true,\n' - ' "interpolation": "Discrete"\n' - "}", - ), - ( - tbs, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-02T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true,\n' - ' "interpolation": "Step"\n' - "}", - ), - ( - tbss, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-05T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "sequences": [\n' - " {\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - " {\n" - ' "values": [\n' - " true,\n" - " true\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-03T00:00:00+00",\n' - ' "2019-09-05T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " }\n" - " ],\n" - ' "interpolation": "Step"\n' - "}", + tbi, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-01T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00"\n' + " ],\n" + ' "interpolation": "None"\n' + "}", + ), + ( + tbds, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-02T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true,\n' + ' "interpolation": "Discrete"\n' + "}", + ), + ( + tbs, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-02T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true,\n' + ' "interpolation": "Step"\n' + "}", + ), + ( + tbss, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-05T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "sequences": [\n' + " {\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + " {\n" + ' "values": [\n' + " true,\n" + " true\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-03T00:00:00+00",\n' + ' "2019-09-05T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " }\n" + " ],\n" + ' "interpolation": "Step"\n' + "}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -711,13 +756,13 @@ def test_instant_n(self, temporal, n, expected): (tbds, [tbi, TBoolInst("False@2019-09-02")]), (tbs, [tbi, TBoolInst("False@2019-09-02")]), ( - tbss, - [ - tbi, - TBoolInst("False@2019-09-02"), - TBoolInst("True@2019-09-03"), - TBoolInst("True@2019-09-05"), - ], + tbss, + [ + tbi, + TBoolInst("False@2019-09-02"), + TBoolInst("True@2019-09-03"), + TBoolInst("True@2019-09-05"), + ], ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -782,27 +827,27 @@ def test_timestamp_n(self, temporal, n, expected): [ (tbi, [datetime(year=2019, month=9, day=1, tzinfo=timezone.utc)]), ( - tbds, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - ], + tbds, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + ], ), ( - tbs, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - ], + tbs, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + ], ), ( - tbss, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=3, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=5, tzinfo=timezone.utc), - ], + tbss, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=3, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=5, tzinfo=timezone.utc), + ], ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -815,16 +860,16 @@ def test_timestamps(self, temporal, expected): [ (tbds, [TBoolSeq("[t@2019-09-01]"), TBoolSeq("[f@2019-09-02]")]), ( - tbs, - [TBoolSeq("[t@2019-09-01, t@2019-09-02)"), TBoolSeq("[f@2019-09-02]")], + tbs, + [TBoolSeq("[t@2019-09-01, t@2019-09-02)"), TBoolSeq("[f@2019-09-02]")], ), ( - tbss, - [ - TBoolSeq("[t@2019-09-01, t@2019-09-02)"), - TBoolSeq("[f@2019-09-02]"), - TBoolSeq("[t@2019-09-03, t@2019-09-05]"), - ], + tbss, + [ + TBoolSeq("[t@2019-09-01, t@2019-09-02)"), + TBoolSeq("[f@2019-09-02]"), + TBoolSeq("[t@2019-09-03, t@2019-09-05]"), + ], ), ], ids=["Discrete Sequence", "Sequence", "SequenceSet"], @@ -901,24 +946,24 @@ def test_to_instant(self, temporal, expected): "temporal, interpolation, expected", [ ( - TBoolInst("True@2019-09-01"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01]"), + TBoolInst("True@2019-09-01"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01]"), ), ( - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), - TInterpolation.DISCRETE, - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TInterpolation.DISCRETE, + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), ), ( - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), ), ( - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -932,24 +977,24 @@ def test_to_sequence(self, temporal, interpolation, expected): "temporal, interpolation, expected", [ ( - TBoolInst("True@2019-09-01"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01]}"), + TBoolInst("True@2019-09-01"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01]}"), ), ( - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01], [False@2019-09-02]}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01], [False@2019-09-02]}"), ), ( - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), ), ( - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -969,56 +1014,56 @@ def test_to_sequenceset(self, temporal, interpolation, expected): (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-05, False@2019-09-06}")), (tbds, timedelta(days=-4), TBoolSeq("{True@2019-08-28, False@2019-08-29}")), ( - tbds, - timedelta(hours=2), - TBoolSeq("{True@2019-09-01 02:00:00, False@2019-09-02 02:00:00}"), + tbds, + timedelta(hours=2), + TBoolSeq("{True@2019-09-01 02:00:00, False@2019-09-02 02:00:00}"), ), ( - tbds, - timedelta(hours=-2), - TBoolSeq("{True@2019-08-31 22:00:00, False@2019-09-01 22:00:00}"), + tbds, + timedelta(hours=-2), + TBoolSeq("{True@2019-08-31 22:00:00, False@2019-09-01 22:00:00}"), ), (tbs, timedelta(days=4), TBoolSeq("[True@2019-09-05, False@2019-09-06]")), (tbs, timedelta(days=-4), TBoolSeq("[True@2019-08-28, False@2019-08-29]")), ( - tbs, - timedelta(hours=2), - TBoolSeq("[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]"), + tbs, + timedelta(hours=2), + TBoolSeq("[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]"), ), ( - tbs, - timedelta(hours=-2), - TBoolSeq("[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]"), + tbs, + timedelta(hours=-2), + TBoolSeq("[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]"), ), ( - tbss, - timedelta(days=4), - TBoolSeqSet( - "{[True@2019-09-05, False@2019-09-06],[True@2019-09-07, True@2019-09-09]}" - ), + tbss, + timedelta(days=4), + TBoolSeqSet( + "{[True@2019-09-05, False@2019-09-06],[True@2019-09-07, True@2019-09-09]}" + ), ), ( - tbss, - timedelta(days=-4), - TBoolSeqSet( - "{[True@2019-08-28, False@2019-08-29],[True@2019-08-30, True@2019-09-01]}" - ), + tbss, + timedelta(days=-4), + TBoolSeqSet( + "{[True@2019-08-28, False@2019-08-29],[True@2019-08-30, True@2019-09-01]}" + ), ), ( - tbss, - timedelta(hours=2), - TBoolSeqSet( - "{[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]," - "[True@2019-09-03 02:00:00, True@2019-09-05 02:00:00]}" - ), + tbss, + timedelta(hours=2), + TBoolSeqSet( + "{[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]," + "[True@2019-09-03 02:00:00, True@2019-09-05 02:00:00]}" + ), ), ( - tbss, - timedelta(hours=-2), - TBoolSeqSet( - "{[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]," - "[True@2019-09-02 22:00:00, True@2019-09-04 22:00:00]}" - ), + tbss, + timedelta(hours=-2), + TBoolSeqSet( + "{[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]," + "[True@2019-09-02 22:00:00, True@2019-09-04 22:00:00]}" + ), ), ], ids=[ @@ -1050,30 +1095,30 @@ def test_shift_time(self, tbool, delta, expected): (tbi, timedelta(hours=2), TBoolInst("True@2019-09-01")), (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-01, False@2019-09-05}")), ( - tbds, - timedelta(hours=2), - TBoolSeq("{True@2019-09-01 00:00:00, False@2019-09-01 02:00:00}"), + tbds, + timedelta(hours=2), + TBoolSeq("{True@2019-09-01 00:00:00, False@2019-09-01 02:00:00}"), ), (tbs, timedelta(days=4), TBoolSeq("[True@2019-09-01, False@2019-09-05]")), ( - tbs, - timedelta(hours=2), - TBoolSeq("[True@2019-09-01 00:00:00, False@2019-09-01 02:00:00]"), + tbs, + timedelta(hours=2), + TBoolSeq("[True@2019-09-01 00:00:00, False@2019-09-01 02:00:00]"), ), ( - tbss, - timedelta(days=4), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timedelta(days=4), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - timedelta(hours=2), - TBoolSeqSet( - "{[True@2019-09-01 00:00:00, False@2019-09-01 00:30:00]," - "[True@2019-09-01 01:00:00, True@2019-09-01 02:00:00]}" - ), + tbss, + timedelta(hours=2), + TBoolSeqSet( + "{[True@2019-09-01 00:00:00, False@2019-09-01 00:30:00]," + "[True@2019-09-01 01:00:00, True@2019-09-01 02:00:00]}" + ), ), ], ids=[ @@ -1105,27 +1150,27 @@ def test_shift_scale_time(self): (tbi, timedelta(hours=12), TBoolInst("True@2019-09-01")), (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-01}")), ( - tbds, - timedelta(hours=12), - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + tbds, + timedelta(hours=12), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), ), (tbs, timedelta(days=4), TBoolSeq("{True@2019-09-01}")), ( - tbs, - timedelta(hours=12), - TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02}" - ), + tbs, + timedelta(hours=12), + TBoolSeq( + "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02}" + ), ), (tbss, timedelta(days=4), TBoolSeq("{True@2019-09-01,True@2019-09-05}")), ( - tbss, - timedelta(hours=12), - TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02," - "True@2019-09-03, True@2019-09-03 12:00:00, True@2019-09-04, " - "True@2019-09-04 12:00:00, True@2019-09-05}" - ), + tbss, + timedelta(hours=12), + TBoolSeq( + "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02," + "True@2019-09-03, True@2019-09-03 12:00:00, True@2019-09-04, " + "True@2019-09-04 12:00:00, True@2019-09-05}" + ), ), ], ids=[ @@ -1155,26 +1200,26 @@ class TestTBoolModifications(TestTBool): "temporal, sequence, expected", [ ( - tbi, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, True@2019-09-03}"), + tbi, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, True@2019-09-03}"), ), ( - tbds, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolSeq("[True@2019-09-03]"), - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02, True@2019-09-03]}"), + tbs, + TBoolSeq("[True@2019-09-03]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02, True@2019-09-03]}"), ), ( - tbss, - TBoolSeq("[True@2019-09-06]"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" - ), + tbss, + TBoolSeq("[True@2019-09-06]"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1187,23 +1232,23 @@ def test_insert(self, temporal, sequence, expected): [ (tbi, TBoolInst("False@2019-09-01"), TBoolInst("False@2019-09-01")), ( - tbds, - TBoolInst("False@2019-09-01"), - TBoolSeq("{False@2019-09-01, False@2019-09-02}"), + tbds, + TBoolInst("False@2019-09-01"), + TBoolSeq("{False@2019-09-01, False@2019-09-02}"), ), ( - tbs, - TBoolInst("False@2019-09-01"), - TBoolSeqSet( - "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02]}" - ), + tbs, + TBoolInst("False@2019-09-01"), + TBoolSeqSet( + "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02]}" + ), ), ( - tbss, - TBoolInst("False@2019-09-01"), - TBoolSeqSet( - "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolInst("False@2019-09-01"), + TBoolSeqSet( + "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1217,21 +1262,21 @@ def test_update(self, temporal, instant, expected): (tbi, datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), None), (tbi, datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), tbi), ( - tbds, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeq("{False@2019-09-02}"), + tbds, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeq("{False@2019-09-02}"), ), ( - tbs, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeqSet("{(True@2019-09-01, False@2019-09-02]}"), + tbs, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeqSet("{(True@2019-09-01, False@2019-09-02]}"), ), ( - tbss, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=[ @@ -1249,26 +1294,26 @@ def test_delete(self, temporal, time, expected): "temporal, instant, expected", [ ( - tbi, - TBoolInst("True@2019-09-02"), - TBoolSeq("[True@2019-09-01, True@2019-09-02]"), + tbi, + TBoolInst("True@2019-09-02"), + TBoolSeq("[True@2019-09-01, True@2019-09-02]"), ), ( - tbds, - TBoolInst("True@2019-09-03"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolInst("True@2019-09-03"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolInst("True@2019-09-03"), - TBoolSeq("[True@2019-09-01, False@2019-09-02, True@2019-09-03]"), + tbs, + TBoolInst("True@2019-09-03"), + TBoolSeq("[True@2019-09-01, False@2019-09-02, True@2019-09-03]"), ), ( - tbss, - TBoolInst("True@2019-09-06"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-06]}" - ), + tbss, + TBoolInst("True@2019-09-06"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-06]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1280,21 +1325,21 @@ def test_append_instant(self, temporal, instant, expected): "temporal, sequence, expected", [ ( - tbds, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolSeq("[True@2019-09-03]"), - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02], [True@2019-09-03]}"), + tbs, + TBoolSeq("[True@2019-09-03]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02], [True@2019-09-03]}"), ), ( - tbss, - TBoolSeq("[True@2019-09-06]"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" - ), + tbss, + TBoolSeq("[True@2019-09-06]"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" + ), ), ], ids=["Discrete Sequence", "Sequence", "SequenceSet"], @@ -1319,21 +1364,21 @@ class TestTBoolManipulationFunctions(TestTBool): (tbds, timedelta(days=1), TBoolSeq("{True@2019-09-02, False@2019-09-03}")), (tbs, timedelta(days=1), TBoolSeq("[True@2019-09-02, False@2019-09-03]")), ( - tbss, - timedelta(days=1), - TBoolSeqSet( - "{[True@2019-09-02, False@2019-09-03],[True@2019-09-04, True@2019-09-06]}" - ), + tbss, + timedelta(days=1), + TBoolSeqSet( + "{[True@2019-09-02, False@2019-09-03],[True@2019-09-04, True@2019-09-06]}" + ), ), (tbi, timedelta(days=-1), TBoolInst("True@2019-08-31")), (tbds, timedelta(days=-1), TBoolSeq("{True@2019-08-31, False@2019-09-01}")), (tbs, timedelta(days=-1), TBoolSeq("[True@2019-08-31, False@2019-09-01]")), ( - tbss, - timedelta(days=-1), - TBoolSeqSet( - "{[True@2019-08-31, False@2019-09-01],[True@2019-09-02, True@2019-09-04]}" - ), + tbss, + timedelta(days=-1), + TBoolSeqSet( + "{[True@2019-08-31, False@2019-09-01],[True@2019-09-02, True@2019-09-04]}" + ), ), ], ids=[ @@ -1357,11 +1402,11 @@ def test_shift_time(self, temporal, shift, expected): (tbds, timedelta(days=10), TBoolSeq("{True@2019-09-01, False@2019-09-11}")), (tbs, timedelta(days=10), TBoolSeq("[True@2019-09-01, False@2019-09-11]")), ( - tbss, - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-03 12:00:00],[True@2019-09-06, True@2019-09-11]}" - ), + tbss, + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-03 12:00:00],[True@2019-09-06, True@2019-09-11]}" + ), ), ], ids=[ @@ -1379,45 +1424,45 @@ def test_scale_time(self, temporal, scale, expected): [ (tbi, timedelta(days=1), timedelta(days=10), TBoolInst("True@2019-09-02")), ( - tbds, - timedelta(days=1), - timedelta(days=10), - TBoolSeq("{True@2019-09-02, False@2019-09-12}"), + tbds, + timedelta(days=1), + timedelta(days=10), + TBoolSeq("{True@2019-09-02, False@2019-09-12}"), ), ( - tbs, - timedelta(days=1), - timedelta(days=10), - TBoolSeq("[True@2019-09-02, False@2019-09-12]"), + tbs, + timedelta(days=1), + timedelta(days=10), + TBoolSeq("[True@2019-09-02, False@2019-09-12]"), ), ( - tbss, - timedelta(days=1), - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-09-02, False@2019-09-04 12:00:00],[True@2019-09-07, True@2019-09-12]}" - ), + tbss, + timedelta(days=1), + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-09-02, False@2019-09-04 12:00:00],[True@2019-09-07, True@2019-09-12]}" + ), ), (tbi, timedelta(days=-1), timedelta(days=10), TBoolInst("True@2019-08-31")), ( - tbds, - timedelta(days=-1), - timedelta(days=10), - TBoolSeq("{True@2019-08-31, False@2019-09-10}"), + tbds, + timedelta(days=-1), + timedelta(days=10), + TBoolSeq("{True@2019-08-31, False@2019-09-10}"), ), ( - tbs, - timedelta(days=-1), - timedelta(days=10), - TBoolSeq("[True@2019-08-31, False@2019-09-10]"), + tbs, + timedelta(days=-1), + timedelta(days=10), + TBoolSeq("[True@2019-08-31, False@2019-09-10]"), ), ( - tbss, - timedelta(days=-1), - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-08-31, False@2019-09-02 12:00:00],[True@2019-09-05, True@2019-09-010]}" - ), + tbss, + timedelta(days=-1), + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-08-31, False@2019-09-02 12:00:00],[True@2019-09-05, True@2019-09-010]}" + ), ), ], ids=[ @@ -1499,18 +1544,18 @@ def test_when_false(self, temporal, expected): (tbss, timestamp_set, TBoolSeq("{True@2019-09-01, True@2019-09-03}")), (tbss, tstzspan, TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}")), ( - tbss, - tstzspan_set, - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + tstzspan_set, + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - True, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + True, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), (tbss, False, TBoolSeqSet("{[False@2019-09-02]}")), ], @@ -1551,10 +1596,10 @@ def test_at(self, temporal, restrictor, expected): (tbds, TBoolSeq("{True@2019-09-01}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02)")), ( - tbss, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1597,28 +1642,28 @@ def test_at_min(self, temporal, expected): (tbs, True, TBoolSeqSet("{[False@2019-09-02]}")), (tbs, False, TBoolSeqSet("{[True@2019-09-01, True@2019-09-02)}")), ( - tbss, - timestamp, - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timestamp, + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - timestamp_set, - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],(True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timestamp_set, + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],(True@2019-09-03, True@2019-09-05]}" + ), ), (tbss, tstzspan, TBoolSeqSet("{[True@2019-09-03, True@2019-09-05]}")), (tbss, tstzspan_set, None), (tbss, True, TBoolSeqSet("{[False@2019-09-02]}")), ( - tbss, - False, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + False, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=[ @@ -1671,10 +1716,10 @@ def test_minus_max(self, temporal, expected): (tbds, TBoolSeq("{True@2019-09-01}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02)")), ( - tbss, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1739,8 +1784,8 @@ def test_minus_min(self, temporal, expected): ) def test_at_minus(self, temporal, restrictor): assert ( - TBool.from_merge(temporal.at(restrictor), temporal.minus(restrictor)) - == temporal + TBool.from_merge(temporal.at(restrictor), temporal.minus(restrictor)) + == temporal ) @pytest.mark.parametrize( @@ -1851,10 +1896,10 @@ class TestTBoolTemporalComparisons(TestTBool): (tbds, TBoolSeq("{False@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet( - "{[False@2019-09-01, True@2019-09-02],[False@2019-09-03, False@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[False@2019-09-01, True@2019-09-02],[False@2019-09-03, False@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1871,8 +1916,8 @@ def test_temporal_not(self, temporal, expected): (tbds, TBoolSeq("{False@2019-09-01, False@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, False@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1900,8 +1945,8 @@ def test_temporal_and_bool(self, temporal): (tbds, TBoolSeq("{True@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1929,8 +1974,8 @@ def test_temporal_or_bool(self, temporal): (tbds, TBoolSeq("{False@2019-09-01, False@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, False@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1955,8 +2000,8 @@ def test_temporal_equal_bool(self, temporal): (tbds, TBoolSeq("{True@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[False@2019-09-03]}"), + tbss, + TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[False@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], From de3b67d302780b7c7d9a79533549fc7abaca9188 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:11:54 +0200 Subject: [PATCH 3/9] Add test for linera interpolation --- tests/main/tbool_test.py | 1006 +++++++++++++++++++------------------- 1 file changed, 507 insertions(+), 499 deletions(-) diff --git a/tests/main/tbool_test.py b/tests/main/tbool_test.py index 3b13ef1f..ecbcb949 100644 --- a/tests/main/tbool_test.py +++ b/tests/main/tbool_test.py @@ -37,21 +37,21 @@ class TestTBoolConstructors(TestTBool): [ (TIntInst("1@2019-09-01"), TBoolInst, TInterpolation.NONE), ( - TIntSeq("{1@2019-09-01, 0@2019-09-02}"), - TBoolSeq, - TInterpolation.DISCRETE, + TIntSeq("{1@2019-09-01, 0@2019-09-02}"), + TBoolSeq, + TInterpolation.DISCRETE, ), ( - TIntSeq("[1@2019-09-01, 0@2019-09-02]"), - TBoolSeq, - TInterpolation.STEPWISE, + TIntSeq("[1@2019-09-01, 0@2019-09-02]"), + TBoolSeq, + TInterpolation.STEPWISE, ), ( - TIntSeqSet( - "{[1@2019-09-01, 0@2019-09-02],[1@2019-09-03, 1@2019-09-05]}" - ), - TBoolSeqSet, - TInterpolation.STEPWISE, + TIntSeqSet( + "{[1@2019-09-01, 0@2019-09-02],[1@2019-09-03, 1@2019-09-05]}" + ), + TBoolSeqSet, + TInterpolation.STEPWISE, ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -66,15 +66,15 @@ def test_from_base_constructor(self, source, type, interpolation): [ (datetime(2000, 1, 1), TBoolInst, TInterpolation.NONE), ( - TsTzSet("{2019-09-01, 2019-09-02}"), - TBoolSeq, - TInterpolation.DISCRETE, + TsTzSet("{2019-09-01, 2019-09-02}"), + TBoolSeq, + TInterpolation.DISCRETE, ), (TsTzSpan("[2019-09-01, 2019-09-02]"), TBoolSeq, TInterpolation.STEPWISE), ( - TsTzSpanSet("{[2019-09-01, 2019-09-02],[2019-09-03, 2019-09-05]}"), - TBoolSeqSet, - TInterpolation.STEPWISE, + TsTzSpanSet("{[2019-09-01, 2019-09-02],[2019-09-03, 2019-09-05]}"), + TBoolSeqSet, + TInterpolation.STEPWISE, ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -88,29 +88,29 @@ def test_from_base_time_constructor(self, source, type, interpolation): "source, type, interpolation, expected", [ ( - "True@2019-09-01", - TBoolInst, - TInterpolation.NONE, - "t@2019-09-01 00:00:00+00", + "True@2019-09-01", + TBoolInst, + TInterpolation.NONE, + "t@2019-09-01 00:00:00+00", ), ( - "{True@2019-09-01, False@2019-09-02}", - TBoolSeq, - TInterpolation.DISCRETE, - "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}", + "{True@2019-09-01, False@2019-09-02}", + TBoolSeq, + TInterpolation.DISCRETE, + "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}", ), ( - "[True@2019-09-01, False@2019-09-02]", - TBoolSeq, - TInterpolation.STEPWISE, - "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]", + "[True@2019-09-01, False@2019-09-02]", + TBoolSeq, + TInterpolation.STEPWISE, + "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]", ), ( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}", - TBoolSeqSet, - TInterpolation.STEPWISE, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}", + TBoolSeqSet, + TInterpolation.STEPWISE, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -125,16 +125,16 @@ def test_string_constructor(self, source, type, interpolation, expected): "source, type, expected", [ ( - "[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]", - TBoolSeq, - "[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00]", + "[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]", + TBoolSeq, + "[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00]", ), ( - "{[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]," - "[True@2019-09-07, True@2019-09-08, True@2019-09-09]}", - TBoolSeqSet, - "{[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00], " - "[t@2019-09-07 00:00:00+00, t@2019-09-09 00:00:00+00]}", + "{[True@2019-09-01, True@2019-09-02, True@2019-09-03, False@2019-09-05]," + "[True@2019-09-07, True@2019-09-08, True@2019-09-09]}", + TBoolSeqSet, + "{[t@2019-09-01 00:00:00+00, f@2019-09-05 00:00:00+00], " + "[t@2019-09-07 00:00:00+00, t@2019-09-09 00:00:00+00]}", ), ], ids=["Sequence", "SequenceSet"], @@ -162,62 +162,62 @@ def test_value_timestamp_instant_constructor(self, value, timestamp): "list, interpolation, normalize, expected", [ ( - ["True@2019-09-01", "False@2019-09-03"], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + ["True@2019-09-01", "False@2019-09-03"], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - ["True@2019-09-01", "False@2019-09-03"], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "False@2019-09-03"], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + [TBoolInst("True@2019-09-01"), TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", TBoolInst("False@2019-09-03")], - TInterpolation.DISCRETE, - False, - "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", + ["True@2019-09-01", TBoolInst("False@2019-09-03")], + TInterpolation.DISCRETE, + False, + "{t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00}", ), ( - ["True@2019-09-01", TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - False, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + False, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", "True@2019-09-02", "False@2019-09-03"], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "True@2019-09-02", "False@2019-09-03"], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - [ - TBoolInst("True@2019-09-01"), - TBoolInst("True@2019-09-02"), - TBoolInst("False@2019-09-03"), - ], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + [ + TBoolInst("True@2019-09-01"), + TBoolInst("True@2019-09-02"), + TBoolInst("False@2019-09-03"), + ], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ( - ["True@2019-09-01", "True@2019-09-02", TBoolInst("False@2019-09-03")], - TInterpolation.STEPWISE, - True, - "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", + ["True@2019-09-01", "True@2019-09-02", TBoolInst("False@2019-09-03")], + TInterpolation.STEPWISE, + True, + "[t@2019-09-01 00:00:00+00, f@2019-09-03 00:00:00+00]", ), ], ids=[ @@ -233,7 +233,7 @@ def test_value_timestamp_instant_constructor(self, value, timestamp): ], ) def test_instant_list_sequence_constructor( - self, list, interpolation, normalize, expected + self, list, interpolation, normalize, expected ): tbs = TBoolSeq( instant_list=list, @@ -254,45 +254,53 @@ def test_instant_list_sequence_constructor( "params, result", [ ( - ( - [ - TBoolInst("True@2000-01-01"), - TBoolInst("False@2000-01-02"), - TBoolInst("False@2000-01-05"), - ], - TInterpolation.STEPWISE, - None, - ), - TBoolSeqSet("{[True@2000-01-01, False@2000-01-02, False@2000-01-05]}"), - ), - ( - ( - [ - TBoolInst("True@2000-01-01"), - TBoolInst("False@2000-01-02"), - TBoolInst("False@2000-01-05"), - ], - TInterpolation.STEPWISE, - timedelta(days=2), - ), - TBoolSeqSet("{[True@2000-01-01, False@2000-01-02], [False@2000-01-05]}"), - ) + ( + [ + TBoolInst("True@2000-01-01"), + TBoolInst("False@2000-01-02"), + TBoolInst("False@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TBoolSeqSet("{[True@2000-01-01, False@2000-01-02, False@2000-01-05]}"), + ), + ( + ( + [ + TBoolInst("True@2000-01-01"), + TBoolInst("False@2000-01-02"), + TBoolInst("False@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TBoolSeqSet( + "{[True@2000-01-01, False@2000-01-02], [False@2000-01-05]}" + ), + ), ], ids=["No Gaps", "With Gaps"], ) def test_gaps_constructor(self, params, result): assert TBoolSeqSet.from_instants_with_gaps(*params) == result - def test_gaps_constructor_with_distance_raises(self): + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.STEPWISE, "max_distance": 2}, + {"interpolation": TInterpolation.LINEAR}, + ], + ids=["Max Distance", "Linear Interpolation"], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): instants = [ TBoolInst(value=True, timestamp="2000-01-01"), TBoolInst(value=False, timestamp="2000-01-02"), TBoolInst(value=False, timestamp="2000-01-03"), ] with pytest.raises(MeosException): - TBoolSeqSet.from_instants_with_gaps( - instants, TInterpolation.STEPWISE, max_distance=2 - ) + TBoolSeqSet.from_instants_with_gaps(instants, **params) @pytest.mark.parametrize( "temporal", @@ -331,9 +339,9 @@ class TestTBoolOutputs(TestTBool): (tbds, "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}"), (tbs, "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]"), ( - tbss, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + tbss, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -348,9 +356,9 @@ def test_str(self, temporal, expected): (tbds, "TBoolSeq({t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00})"), (tbs, "TBoolSeq([t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00])"), ( - tbss, - "TBoolSeqSet({[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]})", + tbss, + "TBoolSeqSet({[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]})", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -365,9 +373,9 @@ def test_repr(self, temporal, expected): (tbds, "{t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00}"), (tbs, "[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]"), ( - tbss, - "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " - "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", + tbss, + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00], " + "[t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -382,9 +390,9 @@ def test_as_wkt(self, temporal, expected): (tbds, "0114000602000000030100A01E4E71340200000000F66B85340200"), (tbs, "0114000A02000000030100A01E4E71340200000000F66B85340200"), ( - tbss, - "0114000B0200000002000000030100A01E4E71340200000000F" - "66B853402000200000003010060CD89993402000100207CC5C1340200", + tbss, + "0114000B0200000002000000030100A01E4E71340200000000F" + "66B853402000200000003010060CD89993402000100207CC5C1340200", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -396,108 +404,108 @@ def test_as_hexwkb(self, temporal, expected): "temporal, expected", [ ( - tbi, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-01T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00"\n' - " ],\n" - ' "interpolation": "None"\n' - "}", - ), - ( - tbds, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-02T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true,\n' - ' "interpolation": "Discrete"\n' - "}", - ), - ( - tbs, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-02T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true,\n' - ' "interpolation": "Step"\n' - "}", - ), - ( - tbss, - "{\n" - ' "type": "MovingBoolean",\n' - ' "period": {\n' - ' "begin": "2019-09-01T00:00:00+00",\n' - ' "end": "2019-09-05T00:00:00+00",\n' - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - ' "sequences": [\n' - " {\n" - ' "values": [\n' - " true,\n" - " false\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-01T00:00:00+00",\n' - ' "2019-09-02T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " },\n" - " {\n" - ' "values": [\n' - " true,\n" - " true\n" - " ],\n" - ' "datetimes": [\n' - ' "2019-09-03T00:00:00+00",\n' - ' "2019-09-05T00:00:00+00"\n' - " ],\n" - ' "lower_inc": true,\n' - ' "upper_inc": true\n' - " }\n" - " ],\n" - ' "interpolation": "Step"\n' - "}", + tbi, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-01T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00"\n' + " ],\n" + ' "interpolation": "None"\n' + "}", + ), + ( + tbds, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-02T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true,\n' + ' "interpolation": "Discrete"\n' + "}", + ), + ( + tbs, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-02T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true,\n' + ' "interpolation": "Step"\n' + "}", + ), + ( + tbss, + "{\n" + ' "type": "MovingBoolean",\n' + ' "period": {\n' + ' "begin": "2019-09-01T00:00:00+00",\n' + ' "end": "2019-09-05T00:00:00+00",\n' + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + ' "sequences": [\n' + " {\n" + ' "values": [\n' + " true,\n" + " false\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-01T00:00:00+00",\n' + ' "2019-09-02T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " },\n" + " {\n" + ' "values": [\n' + " true,\n" + " true\n" + " ],\n" + ' "datetimes": [\n' + ' "2019-09-03T00:00:00+00",\n' + ' "2019-09-05T00:00:00+00"\n' + " ],\n" + ' "lower_inc": true,\n' + ' "upper_inc": true\n' + " }\n" + " ],\n" + ' "interpolation": "Step"\n' + "}", ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -756,13 +764,13 @@ def test_instant_n(self, temporal, n, expected): (tbds, [tbi, TBoolInst("False@2019-09-02")]), (tbs, [tbi, TBoolInst("False@2019-09-02")]), ( - tbss, - [ - tbi, - TBoolInst("False@2019-09-02"), - TBoolInst("True@2019-09-03"), - TBoolInst("True@2019-09-05"), - ], + tbss, + [ + tbi, + TBoolInst("False@2019-09-02"), + TBoolInst("True@2019-09-03"), + TBoolInst("True@2019-09-05"), + ], ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -827,27 +835,27 @@ def test_timestamp_n(self, temporal, n, expected): [ (tbi, [datetime(year=2019, month=9, day=1, tzinfo=timezone.utc)]), ( - tbds, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - ], + tbds, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + ], ), ( - tbs, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - ], + tbs, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + ], ), ( - tbss, - [ - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=3, tzinfo=timezone.utc), - datetime(year=2019, month=9, day=5, tzinfo=timezone.utc), - ], + tbss, + [ + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=3, tzinfo=timezone.utc), + datetime(year=2019, month=9, day=5, tzinfo=timezone.utc), + ], ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -860,16 +868,16 @@ def test_timestamps(self, temporal, expected): [ (tbds, [TBoolSeq("[t@2019-09-01]"), TBoolSeq("[f@2019-09-02]")]), ( - tbs, - [TBoolSeq("[t@2019-09-01, t@2019-09-02)"), TBoolSeq("[f@2019-09-02]")], + tbs, + [TBoolSeq("[t@2019-09-01, t@2019-09-02)"), TBoolSeq("[f@2019-09-02]")], ), ( - tbss, - [ - TBoolSeq("[t@2019-09-01, t@2019-09-02)"), - TBoolSeq("[f@2019-09-02]"), - TBoolSeq("[t@2019-09-03, t@2019-09-05]"), - ], + tbss, + [ + TBoolSeq("[t@2019-09-01, t@2019-09-02)"), + TBoolSeq("[f@2019-09-02]"), + TBoolSeq("[t@2019-09-03, t@2019-09-05]"), + ], ), ], ids=["Discrete Sequence", "Sequence", "SequenceSet"], @@ -946,24 +954,24 @@ def test_to_instant(self, temporal, expected): "temporal, interpolation, expected", [ ( - TBoolInst("True@2019-09-01"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01]"), + TBoolInst("True@2019-09-01"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01]"), ), ( - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), - TInterpolation.DISCRETE, - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TInterpolation.DISCRETE, + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), ), ( - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), ), ( - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), - TInterpolation.STEPWISE, - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TInterpolation.STEPWISE, + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -977,24 +985,24 @@ def test_to_sequence(self, temporal, interpolation, expected): "temporal, interpolation, expected", [ ( - TBoolInst("True@2019-09-01"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01]}"), + TBoolInst("True@2019-09-01"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01]}"), ), ( - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01], [False@2019-09-02]}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01], [False@2019-09-02]}"), ), ( - TBoolSeq("[True@2019-09-01, False@2019-09-02]"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TBoolSeq("[True@2019-09-01, False@2019-09-02]"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), ), ( - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), - TInterpolation.STEPWISE, - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), + TInterpolation.STEPWISE, + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1014,56 +1022,56 @@ def test_to_sequenceset(self, temporal, interpolation, expected): (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-05, False@2019-09-06}")), (tbds, timedelta(days=-4), TBoolSeq("{True@2019-08-28, False@2019-08-29}")), ( - tbds, - timedelta(hours=2), - TBoolSeq("{True@2019-09-01 02:00:00, False@2019-09-02 02:00:00}"), + tbds, + timedelta(hours=2), + TBoolSeq("{True@2019-09-01 02:00:00, False@2019-09-02 02:00:00}"), ), ( - tbds, - timedelta(hours=-2), - TBoolSeq("{True@2019-08-31 22:00:00, False@2019-09-01 22:00:00}"), + tbds, + timedelta(hours=-2), + TBoolSeq("{True@2019-08-31 22:00:00, False@2019-09-01 22:00:00}"), ), (tbs, timedelta(days=4), TBoolSeq("[True@2019-09-05, False@2019-09-06]")), (tbs, timedelta(days=-4), TBoolSeq("[True@2019-08-28, False@2019-08-29]")), ( - tbs, - timedelta(hours=2), - TBoolSeq("[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]"), + tbs, + timedelta(hours=2), + TBoolSeq("[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]"), ), ( - tbs, - timedelta(hours=-2), - TBoolSeq("[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]"), + tbs, + timedelta(hours=-2), + TBoolSeq("[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]"), ), ( - tbss, - timedelta(days=4), - TBoolSeqSet( - "{[True@2019-09-05, False@2019-09-06],[True@2019-09-07, True@2019-09-09]}" - ), + tbss, + timedelta(days=4), + TBoolSeqSet( + "{[True@2019-09-05, False@2019-09-06],[True@2019-09-07, True@2019-09-09]}" + ), ), ( - tbss, - timedelta(days=-4), - TBoolSeqSet( - "{[True@2019-08-28, False@2019-08-29],[True@2019-08-30, True@2019-09-01]}" - ), + tbss, + timedelta(days=-4), + TBoolSeqSet( + "{[True@2019-08-28, False@2019-08-29],[True@2019-08-30, True@2019-09-01]}" + ), ), ( - tbss, - timedelta(hours=2), - TBoolSeqSet( - "{[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]," - "[True@2019-09-03 02:00:00, True@2019-09-05 02:00:00]}" - ), + tbss, + timedelta(hours=2), + TBoolSeqSet( + "{[True@2019-09-01 02:00:00, False@2019-09-02 02:00:00]," + "[True@2019-09-03 02:00:00, True@2019-09-05 02:00:00]}" + ), ), ( - tbss, - timedelta(hours=-2), - TBoolSeqSet( - "{[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]," - "[True@2019-09-02 22:00:00, True@2019-09-04 22:00:00]}" - ), + tbss, + timedelta(hours=-2), + TBoolSeqSet( + "{[True@2019-08-31 22:00:00, False@2019-09-01 22:00:00]," + "[True@2019-09-02 22:00:00, True@2019-09-04 22:00:00]}" + ), ), ], ids=[ @@ -1095,30 +1103,30 @@ def test_shift_time(self, tbool, delta, expected): (tbi, timedelta(hours=2), TBoolInst("True@2019-09-01")), (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-01, False@2019-09-05}")), ( - tbds, - timedelta(hours=2), - TBoolSeq("{True@2019-09-01 00:00:00, False@2019-09-01 02:00:00}"), + tbds, + timedelta(hours=2), + TBoolSeq("{True@2019-09-01 00:00:00, False@2019-09-01 02:00:00}"), ), (tbs, timedelta(days=4), TBoolSeq("[True@2019-09-01, False@2019-09-05]")), ( - tbs, - timedelta(hours=2), - TBoolSeq("[True@2019-09-01 00:00:00, False@2019-09-01 02:00:00]"), + tbs, + timedelta(hours=2), + TBoolSeq("[True@2019-09-01 00:00:00, False@2019-09-01 02:00:00]"), ), ( - tbss, - timedelta(days=4), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timedelta(days=4), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - timedelta(hours=2), - TBoolSeqSet( - "{[True@2019-09-01 00:00:00, False@2019-09-01 00:30:00]," - "[True@2019-09-01 01:00:00, True@2019-09-01 02:00:00]}" - ), + tbss, + timedelta(hours=2), + TBoolSeqSet( + "{[True@2019-09-01 00:00:00, False@2019-09-01 00:30:00]," + "[True@2019-09-01 01:00:00, True@2019-09-01 02:00:00]}" + ), ), ], ids=[ @@ -1150,27 +1158,27 @@ def test_shift_scale_time(self): (tbi, timedelta(hours=12), TBoolInst("True@2019-09-01")), (tbds, timedelta(days=4), TBoolSeq("{True@2019-09-01}")), ( - tbds, - timedelta(hours=12), - TBoolSeq("{True@2019-09-01, False@2019-09-02}"), + tbds, + timedelta(hours=12), + TBoolSeq("{True@2019-09-01, False@2019-09-02}"), ), (tbs, timedelta(days=4), TBoolSeq("{True@2019-09-01}")), ( - tbs, - timedelta(hours=12), - TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02}" - ), + tbs, + timedelta(hours=12), + TBoolSeq( + "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02}" + ), ), (tbss, timedelta(days=4), TBoolSeq("{True@2019-09-01,True@2019-09-05}")), ( - tbss, - timedelta(hours=12), - TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02," - "True@2019-09-03, True@2019-09-03 12:00:00, True@2019-09-04, " - "True@2019-09-04 12:00:00, True@2019-09-05}" - ), + tbss, + timedelta(hours=12), + TBoolSeq( + "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02," + "True@2019-09-03, True@2019-09-03 12:00:00, True@2019-09-04, " + "True@2019-09-04 12:00:00, True@2019-09-05}" + ), ), ], ids=[ @@ -1200,26 +1208,26 @@ class TestTBoolModifications(TestTBool): "temporal, sequence, expected", [ ( - tbi, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, True@2019-09-03}"), + tbi, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, True@2019-09-03}"), ), ( - tbds, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolSeq("[True@2019-09-03]"), - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02, True@2019-09-03]}"), + tbs, + TBoolSeq("[True@2019-09-03]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02, True@2019-09-03]}"), ), ( - tbss, - TBoolSeq("[True@2019-09-06]"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" - ), + tbss, + TBoolSeq("[True@2019-09-06]"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1232,23 +1240,23 @@ def test_insert(self, temporal, sequence, expected): [ (tbi, TBoolInst("False@2019-09-01"), TBoolInst("False@2019-09-01")), ( - tbds, - TBoolInst("False@2019-09-01"), - TBoolSeq("{False@2019-09-01, False@2019-09-02}"), + tbds, + TBoolInst("False@2019-09-01"), + TBoolSeq("{False@2019-09-01, False@2019-09-02}"), ), ( - tbs, - TBoolInst("False@2019-09-01"), - TBoolSeqSet( - "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02]}" - ), + tbs, + TBoolInst("False@2019-09-01"), + TBoolSeqSet( + "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02]}" + ), ), ( - tbss, - TBoolInst("False@2019-09-01"), - TBoolSeqSet( - "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolInst("False@2019-09-01"), + TBoolSeqSet( + "{[False@2019-09-01], (True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1262,21 +1270,21 @@ def test_update(self, temporal, instant, expected): (tbi, datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), None), (tbi, datetime(year=2019, month=9, day=2, tzinfo=timezone.utc), tbi), ( - tbds, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeq("{False@2019-09-02}"), + tbds, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeq("{False@2019-09-02}"), ), ( - tbs, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeqSet("{(True@2019-09-01, False@2019-09-02]}"), + tbs, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeqSet("{(True@2019-09-01, False@2019-09-02]}"), ), ( - tbss, - datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + datetime(year=2019, month=9, day=1, tzinfo=timezone.utc), + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=[ @@ -1294,26 +1302,26 @@ def test_delete(self, temporal, time, expected): "temporal, instant, expected", [ ( - tbi, - TBoolInst("True@2019-09-02"), - TBoolSeq("[True@2019-09-01, True@2019-09-02]"), + tbi, + TBoolInst("True@2019-09-02"), + TBoolSeq("[True@2019-09-01, True@2019-09-02]"), ), ( - tbds, - TBoolInst("True@2019-09-03"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolInst("True@2019-09-03"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolInst("True@2019-09-03"), - TBoolSeq("[True@2019-09-01, False@2019-09-02, True@2019-09-03]"), + tbs, + TBoolInst("True@2019-09-03"), + TBoolSeq("[True@2019-09-01, False@2019-09-02, True@2019-09-03]"), ), ( - tbss, - TBoolInst("True@2019-09-06"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-06]}" - ), + tbss, + TBoolInst("True@2019-09-06"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-06]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1325,21 +1333,21 @@ def test_append_instant(self, temporal, instant, expected): "temporal, sequence, expected", [ ( - tbds, - TBoolSeq("{True@2019-09-03}"), - TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), + tbds, + TBoolSeq("{True@2019-09-03}"), + TBoolSeq("{True@2019-09-01, False@2019-09-02, True@2019-09-03}"), ), ( - tbs, - TBoolSeq("[True@2019-09-03]"), - TBoolSeqSet("{[True@2019-09-01, False@2019-09-02], [True@2019-09-03]}"), + tbs, + TBoolSeq("[True@2019-09-03]"), + TBoolSeqSet("{[True@2019-09-01, False@2019-09-02], [True@2019-09-03]}"), ), ( - tbss, - TBoolSeq("[True@2019-09-06]"), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" - ), + tbss, + TBoolSeq("[True@2019-09-06]"), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05],[True@2019-09-06]}" + ), ), ], ids=["Discrete Sequence", "Sequence", "SequenceSet"], @@ -1364,21 +1372,21 @@ class TestTBoolManipulationFunctions(TestTBool): (tbds, timedelta(days=1), TBoolSeq("{True@2019-09-02, False@2019-09-03}")), (tbs, timedelta(days=1), TBoolSeq("[True@2019-09-02, False@2019-09-03]")), ( - tbss, - timedelta(days=1), - TBoolSeqSet( - "{[True@2019-09-02, False@2019-09-03],[True@2019-09-04, True@2019-09-06]}" - ), + tbss, + timedelta(days=1), + TBoolSeqSet( + "{[True@2019-09-02, False@2019-09-03],[True@2019-09-04, True@2019-09-06]}" + ), ), (tbi, timedelta(days=-1), TBoolInst("True@2019-08-31")), (tbds, timedelta(days=-1), TBoolSeq("{True@2019-08-31, False@2019-09-01}")), (tbs, timedelta(days=-1), TBoolSeq("[True@2019-08-31, False@2019-09-01]")), ( - tbss, - timedelta(days=-1), - TBoolSeqSet( - "{[True@2019-08-31, False@2019-09-01],[True@2019-09-02, True@2019-09-04]}" - ), + tbss, + timedelta(days=-1), + TBoolSeqSet( + "{[True@2019-08-31, False@2019-09-01],[True@2019-09-02, True@2019-09-04]}" + ), ), ], ids=[ @@ -1402,11 +1410,11 @@ def test_shift_time(self, temporal, shift, expected): (tbds, timedelta(days=10), TBoolSeq("{True@2019-09-01, False@2019-09-11}")), (tbs, timedelta(days=10), TBoolSeq("[True@2019-09-01, False@2019-09-11]")), ( - tbss, - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-03 12:00:00],[True@2019-09-06, True@2019-09-11]}" - ), + tbss, + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-03 12:00:00],[True@2019-09-06, True@2019-09-11]}" + ), ), ], ids=[ @@ -1424,45 +1432,45 @@ def test_scale_time(self, temporal, scale, expected): [ (tbi, timedelta(days=1), timedelta(days=10), TBoolInst("True@2019-09-02")), ( - tbds, - timedelta(days=1), - timedelta(days=10), - TBoolSeq("{True@2019-09-02, False@2019-09-12}"), + tbds, + timedelta(days=1), + timedelta(days=10), + TBoolSeq("{True@2019-09-02, False@2019-09-12}"), ), ( - tbs, - timedelta(days=1), - timedelta(days=10), - TBoolSeq("[True@2019-09-02, False@2019-09-12]"), + tbs, + timedelta(days=1), + timedelta(days=10), + TBoolSeq("[True@2019-09-02, False@2019-09-12]"), ), ( - tbss, - timedelta(days=1), - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-09-02, False@2019-09-04 12:00:00],[True@2019-09-07, True@2019-09-12]}" - ), + tbss, + timedelta(days=1), + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-09-02, False@2019-09-04 12:00:00],[True@2019-09-07, True@2019-09-12]}" + ), ), (tbi, timedelta(days=-1), timedelta(days=10), TBoolInst("True@2019-08-31")), ( - tbds, - timedelta(days=-1), - timedelta(days=10), - TBoolSeq("{True@2019-08-31, False@2019-09-10}"), + tbds, + timedelta(days=-1), + timedelta(days=10), + TBoolSeq("{True@2019-08-31, False@2019-09-10}"), ), ( - tbs, - timedelta(days=-1), - timedelta(days=10), - TBoolSeq("[True@2019-08-31, False@2019-09-10]"), + tbs, + timedelta(days=-1), + timedelta(days=10), + TBoolSeq("[True@2019-08-31, False@2019-09-10]"), ), ( - tbss, - timedelta(days=-1), - timedelta(days=10), - TBoolSeqSet( - "{[True@2019-08-31, False@2019-09-02 12:00:00],[True@2019-09-05, True@2019-09-010]}" - ), + tbss, + timedelta(days=-1), + timedelta(days=10), + TBoolSeqSet( + "{[True@2019-08-31, False@2019-09-02 12:00:00],[True@2019-09-05, True@2019-09-010]}" + ), ), ], ids=[ @@ -1544,18 +1552,18 @@ def test_when_false(self, temporal, expected): (tbss, timestamp_set, TBoolSeq("{True@2019-09-01, True@2019-09-03}")), (tbss, tstzspan, TBoolSeqSet("{[True@2019-09-01, False@2019-09-02]}")), ( - tbss, - tstzspan_set, - TBoolSeqSet( - "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + tstzspan_set, + TBoolSeqSet( + "{[True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - True, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + True, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), (tbss, False, TBoolSeqSet("{[False@2019-09-02]}")), ], @@ -1596,10 +1604,10 @@ def test_at(self, temporal, restrictor, expected): (tbds, TBoolSeq("{True@2019-09-01}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02)")), ( - tbss, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1642,28 +1650,28 @@ def test_at_min(self, temporal, expected): (tbs, True, TBoolSeqSet("{[False@2019-09-02]}")), (tbs, False, TBoolSeqSet("{[True@2019-09-01, True@2019-09-02)}")), ( - tbss, - timestamp, - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timestamp, + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],[True@2019-09-03, True@2019-09-05]}" + ), ), ( - tbss, - timestamp_set, - TBoolSeqSet( - "{(True@2019-09-01, False@2019-09-02],(True@2019-09-03, True@2019-09-05]}" - ), + tbss, + timestamp_set, + TBoolSeqSet( + "{(True@2019-09-01, False@2019-09-02],(True@2019-09-03, True@2019-09-05]}" + ), ), (tbss, tstzspan, TBoolSeqSet("{[True@2019-09-03, True@2019-09-05]}")), (tbss, tstzspan_set, None), (tbss, True, TBoolSeqSet("{[False@2019-09-02]}")), ( - tbss, - False, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + False, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=[ @@ -1716,10 +1724,10 @@ def test_minus_max(self, temporal, expected): (tbds, TBoolSeq("{True@2019-09-01}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02)")), ( - tbss, - TBoolSeqSet( - "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[True@2019-09-01, True@2019-09-02),[True@2019-09-03, True@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1784,8 +1792,8 @@ def test_minus_min(self, temporal, expected): ) def test_at_minus(self, temporal, restrictor): assert ( - TBool.from_merge(temporal.at(restrictor), temporal.minus(restrictor)) - == temporal + TBool.from_merge(temporal.at(restrictor), temporal.minus(restrictor)) + == temporal ) @pytest.mark.parametrize( @@ -1896,10 +1904,10 @@ class TestTBoolTemporalComparisons(TestTBool): (tbds, TBoolSeq("{False@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet( - "{[False@2019-09-01, True@2019-09-02],[False@2019-09-03, False@2019-09-05]}" - ), + tbss, + TBoolSeqSet( + "{[False@2019-09-01, True@2019-09-02],[False@2019-09-03, False@2019-09-05]}" + ), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1916,8 +1924,8 @@ def test_temporal_not(self, temporal, expected): (tbds, TBoolSeq("{False@2019-09-01, False@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, False@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1945,8 +1953,8 @@ def test_temporal_and_bool(self, temporal): (tbds, TBoolSeq("{True@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -1974,8 +1982,8 @@ def test_temporal_or_bool(self, temporal): (tbds, TBoolSeq("{False@2019-09-01, False@2019-09-02}")), (tbs, TBoolSeq("[False@2019-09-01, False@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), + tbss, + TBoolSeqSet("{[False@2019-09-01, False@2019-09-02],[True@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], @@ -2000,8 +2008,8 @@ def test_temporal_equal_bool(self, temporal): (tbds, TBoolSeq("{True@2019-09-01, True@2019-09-02}")), (tbs, TBoolSeq("[True@2019-09-01, True@2019-09-02]")), ( - tbss, - TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[False@2019-09-03]}"), + tbss, + TBoolSeqSet("{[True@2019-09-01, True@2019-09-02],[False@2019-09-03]}"), ), ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], From 3f3ef3a9275c535237a33e3c4a03e4ea39dd71e6 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:17:29 +0200 Subject: [PATCH 4/9] Add TFloat tests --- tests/main/tfloat_test.py | 132 +++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/tests/main/tfloat_test.py b/tests/main/tfloat_test.py index bf3bc41f..7b795744 100644 --- a/tests/main/tfloat_test.py +++ b/tests/main/tfloat_test.py @@ -3,7 +3,7 @@ from operator import not_ import pytest -from pymeos_cffi import MeosInvalidArgValueError +from pymeos_cffi import MeosInvalidArgValueError, MeosException from pymeos import ( TBoolInst, @@ -259,6 +259,136 @@ def test_instant_list_sequence_constructor( assert str(tfs2) == expected assert tfs2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TFloatSeqSet("Interp=Step;{[1@2000-01-01, 5@2000-01-02, 6@2000-01-05]}"), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + 2.0, + ), + TFloatSeqSet( + "Interp=Step;{[1@2000-01-01], [5@2000-01-02, 6@2000-01-05]}" + ), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TFloatSeqSet( + "Interp=Step;{[1@2000-01-01, 5@2000-01-02], [6@2000-01-05]}" + ), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + 2.0 + ), + TFloatSeqSet( + "Interp=Step;{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}" + ), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + ), + TFloatSeqSet("{[1@2000-01-01, 5@2000-01-02, 6@2000-01-05]}"), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + 2.0, + ), + TFloatSeqSet( + "{[1@2000-01-01], [5@2000-01-02, 6@2000-01-05]}" + ), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + ), + TFloatSeqSet( + "{[1@2000-01-01, 5@2000-01-02], [6@2000-01-05]}" + ), + ), + ( + ( + [ + TFloatInst("1@2000-01-01"), + TFloatInst("5@2000-01-02"), + TFloatInst("6@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + 2.0 + ), + TFloatSeqSet( + "{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}" + ), + ), + ], + ids=[ + "No Gaps Stepwise", + "Value Gaps Stepwise", + "Time Gaps Stepwise", + "Value and Time Gaps Stepwise", + "No Gaps Linear", + "Value Gaps Linear", + "Time Gaps Linear", + "Value and Time Gaps Linear", + ], + ) + def test_gaps_constructor(self, params, result): + assert TFloatSeqSet.from_instants_with_gaps(*params) == result + @pytest.mark.parametrize( "temporal", [tfi, tfds, tfs, tfss, tfsts, tfstss], From 8bee59a4435dce2c32e7c36bc3766c336e231040 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:20:07 +0200 Subject: [PATCH 5/9] Add TInt tests --- tests/main/tint_test.py | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/main/tint_test.py b/tests/main/tint_test.py index bf1cc6b5..1a61766b 100644 --- a/tests/main/tint_test.py +++ b/tests/main/tint_test.py @@ -3,6 +3,7 @@ from operator import not_ import pytest +from pymeos_cffi import MeosException from pymeos import ( TBoolInst, @@ -251,6 +252,85 @@ def test_instant_list_sequence_constructor( assert str(tis2) == expected assert tis2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TIntInst("1@2000-01-01"), + TIntInst("5@2000-01-02"), + TIntInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TIntSeqSet("Interp=Step;{[1@2000-01-01, 5@2000-01-02, 6@2000-01-05]}"), + ), + ( + ( + [ + TIntInst("1@2000-01-01"), + TIntInst("5@2000-01-02"), + TIntInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + 2.0, + ), + TIntSeqSet( + "Interp=Step;{[1@2000-01-01], [5@2000-01-02, 6@2000-01-05]}" + ), + ), + ( + ( + [ + TIntInst("1@2000-01-01"), + TIntInst("5@2000-01-02"), + TIntInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TIntSeqSet( + "Interp=Step;{[1@2000-01-01, 5@2000-01-02], [6@2000-01-05]}" + ), + ), + ( + ( + [ + TIntInst("1@2000-01-01"), + TIntInst("5@2000-01-02"), + TIntInst("6@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + 2.0, + ), + TIntSeqSet( + "Interp=Step;{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}" + ), + ), + ], + ids=[ + "No Gaps Stepwise", + "Value Gaps Stepwise", + "Time Gaps Stepwise", + "Value and Time Gaps Stepwise", + ], + ) + def test_gaps_constructor(self, params, result): + assert TIntSeqSet.from_instants_with_gaps(*params) == result + + def test_gaps_constructor_with_invalid_parameters_raises(self): + instants = [ + TIntInst(value=1, timestamp="2000-01-01"), + TIntInst(value=5, timestamp="2000-01-02"), + TIntInst(value=6, timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TIntSeqSet.from_instants_with_gaps(instants, TInterpolation.LINEAR) + @pytest.mark.parametrize( "temporal", [tii, tids, tis, tiss], From 32e8d34d9a7bada4514018864f4d2138e6e0b425 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:21:48 +0200 Subject: [PATCH 6/9] Add TText tests --- tests/main/ttext_test.py | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/main/ttext_test.py b/tests/main/ttext_test.py index f41bc756..be0fb913 100644 --- a/tests/main/ttext_test.py +++ b/tests/main/ttext_test.py @@ -2,6 +2,7 @@ from datetime import datetime, timezone, timedelta import pytest +from pymeos_cffi import MeosException from pymeos import ( TBool, @@ -252,6 +253,58 @@ def test_instant_list_sequence_constructor( assert str(tts2) == expected assert tts2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TTextInst("A@2000-01-01"), + TTextInst("B@2000-01-02"), + TTextInst("C@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TTextSeqSet("{[A@2000-01-01, B@2000-01-02, C@2000-01-05]}"), + ), + ( + ( + [ + TTextInst("A@2000-01-01"), + TTextInst("B@2000-01-02"), + TTextInst("C@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TTextSeqSet( + "{[A@2000-01-01, B@2000-01-02], [C@2000-01-05]}" + ), + ), + ], + ids=["No Gaps", "With Gaps"], + ) + def test_gaps_constructor(self, params, result): + assert TTextSeqSet.from_instants_with_gaps(*params) == result + + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.STEPWISE, "max_distance": 2}, + {"interpolation": TInterpolation.LINEAR}, + ], + ids=["Max Distance", "Linear Interpolation"], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): + instants = [ + TTextInst(value="A", timestamp="2000-01-01"), + TTextInst(value="B", timestamp="2000-01-02"), + TTextInst(value="C", timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TTextSeqSet.from_instants_with_gaps(instants, **params) + @pytest.mark.parametrize( "temporal", [tti, ttds, tts, ttss], From 3abbb18c91f46f6c0b7a70c625c4de6568446960 Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:30:44 +0200 Subject: [PATCH 7/9] Add Discrete interpolation tests --- tests/main/tbool_test.py | 7 ++++++- tests/main/tfloat_test.py | 18 ++++++++++++++++++ tests/main/tint_test.py | 15 +++++++++++++-- tests/main/ttext_test.py | 3 ++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/main/tbool_test.py b/tests/main/tbool_test.py index ecbcb949..d297e898 100644 --- a/tests/main/tbool_test.py +++ b/tests/main/tbool_test.py @@ -290,8 +290,13 @@ def test_gaps_constructor(self, params, result): [ {"interpolation": TInterpolation.STEPWISE, "max_distance": 2}, {"interpolation": TInterpolation.LINEAR}, + {"interpolation": TInterpolation.DISCRETE}, + ], + ids=[ + "Max Distance", + "Linear Interpolation", + "Discrete Interpolation", ], - ids=["Max Distance", "Linear Interpolation"], ) def test_gaps_constructor_with_invalid_parameters_raises(self, params): instants = [ diff --git a/tests/main/tfloat_test.py b/tests/main/tfloat_test.py index 7b795744..20dd8ccc 100644 --- a/tests/main/tfloat_test.py +++ b/tests/main/tfloat_test.py @@ -389,6 +389,24 @@ def test_instant_list_sequence_constructor( def test_gaps_constructor(self, params, result): assert TFloatSeqSet.from_instants_with_gaps(*params) == result + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.DISCRETE}, + ], + ids=[ + "Discrete Interpolation", + ], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): + instants = [ + TFloatInst(value=1, timestamp="2000-01-01"), + TFloatInst(value=5, timestamp="2000-01-02"), + TFloatInst(value=6, timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TFloatSeqSet.from_instants_with_gaps(instants, **params) + @pytest.mark.parametrize( "temporal", [tfi, tfds, tfs, tfss, tfsts, tfstss], diff --git a/tests/main/tint_test.py b/tests/main/tint_test.py index 1a61766b..29bf4c22 100644 --- a/tests/main/tint_test.py +++ b/tests/main/tint_test.py @@ -322,14 +322,25 @@ def test_instant_list_sequence_constructor( def test_gaps_constructor(self, params, result): assert TIntSeqSet.from_instants_with_gaps(*params) == result - def test_gaps_constructor_with_invalid_parameters_raises(self): + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.LINEAR}, + {"interpolation": TInterpolation.DISCRETE}, + ], + ids=[ + "Linear Interpolation", + "Discrete Interpolation", + ], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): instants = [ TIntInst(value=1, timestamp="2000-01-01"), TIntInst(value=5, timestamp="2000-01-02"), TIntInst(value=6, timestamp="2000-01-03"), ] with pytest.raises(MeosException): - TIntSeqSet.from_instants_with_gaps(instants, TInterpolation.LINEAR) + TIntSeqSet.from_instants_with_gaps(instants, **params) @pytest.mark.parametrize( "temporal", diff --git a/tests/main/ttext_test.py b/tests/main/ttext_test.py index be0fb913..9d217b74 100644 --- a/tests/main/ttext_test.py +++ b/tests/main/ttext_test.py @@ -293,8 +293,9 @@ def test_gaps_constructor(self, params, result): [ {"interpolation": TInterpolation.STEPWISE, "max_distance": 2}, {"interpolation": TInterpolation.LINEAR}, + {"interpolation": TInterpolation.DISCRETE}, ], - ids=["Max Distance", "Linear Interpolation"], + ids=["Max Distance", "Linear Interpolation", "Discrete Interpolation"], ) def test_gaps_constructor_with_invalid_parameters_raises(self, params): instants = [ From c51c59a6318fd55424c98cf80372c55a5dbbc50b Mon Sep 17 00:00:00 2001 From: Diviloper Date: Mon, 6 May 2024 23:40:45 +0200 Subject: [PATCH 8/9] Add TPoint Tests --- tests/main/tgeogpoint_test.py | 154 +++++++++++++++++++++++++++++++++- tests/main/tgeompoint_test.py | 154 +++++++++++++++++++++++++++++++++- 2 files changed, 306 insertions(+), 2 deletions(-) diff --git a/tests/main/tgeogpoint_test.py b/tests/main/tgeogpoint_test.py index d7cadfcd..451a8295 100644 --- a/tests/main/tgeogpoint_test.py +++ b/tests/main/tgeogpoint_test.py @@ -5,7 +5,7 @@ import numpy as np import pytest import shapely.geometry -from pymeos_cffi import MeosInvalidArgValueError +from pymeos_cffi import MeosInvalidArgValueError, MeosException from shapely import Point, LineString, set_srid from pymeos import ( @@ -297,6 +297,158 @@ def test_instant_list_sequence_constructor( assert str(tps2) == expected assert tps2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TGeogPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + 200000.0, + ), + TGeogPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TGeogPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + 200000.0, + ), + TGeogPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + ), + TGeogPointSeqSet( + "{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + 200000.0, + ), + TGeogPointSeqSet( + "{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + ), + TGeogPointSeqSet( + "{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeogPointInst("POINT(1 1)@2000-01-01"), + TGeogPointInst("POINT(5 5)@2000-01-02"), + TGeogPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + 200000.0, + ), + TGeogPointSeqSet( + "{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ], + ids=[ + "No Gaps Stepwise", + "Value Gaps Stepwise", + "Time Gaps Stepwise", + "Value and Time Gaps Stepwise", + "No Gaps Linear", + "Value Gaps Linear", + "Time Gaps Linear", + "Value and Time Gaps Linear", + ], + ) + def test_gaps_constructor(self, params, result): + assert TGeogPointSeqSet.from_instants_with_gaps(*params) == result + + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.DISCRETE}, + ], + ids=[ + "Discrete Interpolation", + ], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): + instants = [ + TGeogPointInst(point="POINT(1 1)", timestamp="2000-01-01"), + TGeogPointInst(point="POINT(5 5)", timestamp="2000-01-02"), + TGeogPointInst(point="POINT(6 6)", timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TGeogPointSeqSet.from_instants_with_gaps(instants, **params) + @pytest.mark.parametrize( "temporal", [tpi, tpds, tps, tpss, tpi3d, tpds3d, tps3d, tpss3d], diff --git a/tests/main/tgeompoint_test.py b/tests/main/tgeompoint_test.py index 5019ceb0..b6e43955 100644 --- a/tests/main/tgeompoint_test.py +++ b/tests/main/tgeompoint_test.py @@ -5,7 +5,7 @@ import pytest import math import numpy as np -from pymeos_cffi import MeosInvalidArgValueError +from pymeos_cffi import MeosInvalidArgValueError, MeosException from shapely import Point, LineString, Polygon, MultiPoint, GeometryCollection from pymeos import ( @@ -289,6 +289,158 @@ def test_instant_list_sequence_constructor( assert str(tps2) == expected assert tps2.interpolation() == interpolation + @pytest.mark.parametrize( + "params, result", + [ + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + ), + TGeomPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + None, + 2.0, + ), + TGeomPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + ), + TGeomPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.STEPWISE, + timedelta(days=2), + 2.0, + ), + TGeomPointSeqSet( + "Interp=Step;{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + ), + TGeomPointSeqSet( + "{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + None, + 2.0, + ), + TGeomPointSeqSet( + "{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02, POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + ), + TGeomPointSeqSet( + "{[POINT(1 1)@2000-01-01, POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ( + ( + [ + TGeomPointInst("POINT(1 1)@2000-01-01"), + TGeomPointInst("POINT(5 5)@2000-01-02"), + TGeomPointInst("POINT(6 6)@2000-01-05"), + ], + TInterpolation.LINEAR, + timedelta(days=2), + 2.0, + ), + TGeomPointSeqSet( + "{[POINT(1 1)@2000-01-01], [POINT(5 5)@2000-01-02], [POINT(6 6)@2000-01-05]}" + ), + ), + ], + ids=[ + "No Gaps Stepwise", + "Value Gaps Stepwise", + "Time Gaps Stepwise", + "Value and Time Gaps Stepwise", + "No Gaps Linear", + "Value Gaps Linear", + "Time Gaps Linear", + "Value and Time Gaps Linear", + ], + ) + def test_gaps_constructor(self, params, result): + assert TGeomPointSeqSet.from_instants_with_gaps(*params) == result + + @pytest.mark.parametrize( + "params", + [ + {"interpolation": TInterpolation.DISCRETE}, + ], + ids=[ + "Discrete Interpolation", + ], + ) + def test_gaps_constructor_with_invalid_parameters_raises(self, params): + instants = [ + TGeomPointInst(point="POINT(1 1)", timestamp="2000-01-01"), + TGeomPointInst(point="POINT(5 5)", timestamp="2000-01-02"), + TGeomPointInst(point="POINT(6 6)", timestamp="2000-01-03"), + ] + with pytest.raises(MeosException): + TGeomPointSeqSet.from_instants_with_gaps(instants, **params) + @pytest.mark.parametrize( "temporal", [tpi, tpds, tps, tpss, tpi3d, tpds3d, tps3d, tpss3d], From 19fe883309e014f094a160ca8177e90b6ebd806e Mon Sep 17 00:00:00 2001 From: Diviloper Date: Sun, 12 May 2024 20:42:23 +0200 Subject: [PATCH 9/9] Run black formatter --- tests/main/tfloat_test.py | 20 ++++++++------------ tests/main/ttext_test.py | 4 +--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/main/tfloat_test.py b/tests/main/tfloat_test.py index 20dd8ccc..67bf5d93 100644 --- a/tests/main/tfloat_test.py +++ b/tests/main/tfloat_test.py @@ -272,7 +272,9 @@ def test_instant_list_sequence_constructor( TInterpolation.STEPWISE, None, ), - TFloatSeqSet("Interp=Step;{[1@2000-01-01, 5@2000-01-02, 6@2000-01-05]}"), + TFloatSeqSet( + "Interp=Step;{[1@2000-01-01, 5@2000-01-02, 6@2000-01-05]}" + ), ), ( ( @@ -312,7 +314,7 @@ def test_instant_list_sequence_constructor( ], TInterpolation.STEPWISE, timedelta(days=2), - 2.0 + 2.0, ), TFloatSeqSet( "Interp=Step;{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}" @@ -341,9 +343,7 @@ def test_instant_list_sequence_constructor( None, 2.0, ), - TFloatSeqSet( - "{[1@2000-01-01], [5@2000-01-02, 6@2000-01-05]}" - ), + TFloatSeqSet("{[1@2000-01-01], [5@2000-01-02, 6@2000-01-05]}"), ), ( ( @@ -355,9 +355,7 @@ def test_instant_list_sequence_constructor( TInterpolation.LINEAR, timedelta(days=2), ), - TFloatSeqSet( - "{[1@2000-01-01, 5@2000-01-02], [6@2000-01-05]}" - ), + TFloatSeqSet("{[1@2000-01-01, 5@2000-01-02], [6@2000-01-05]}"), ), ( ( @@ -368,11 +366,9 @@ def test_instant_list_sequence_constructor( ], TInterpolation.LINEAR, timedelta(days=2), - 2.0 - ), - TFloatSeqSet( - "{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}" + 2.0, ), + TFloatSeqSet("{[1@2000-01-01], [5@2000-01-02], [6@2000-01-05]}"), ), ], ids=[ diff --git a/tests/main/ttext_test.py b/tests/main/ttext_test.py index 9d217b74..38b988b8 100644 --- a/tests/main/ttext_test.py +++ b/tests/main/ttext_test.py @@ -278,9 +278,7 @@ def test_instant_list_sequence_constructor( TInterpolation.STEPWISE, timedelta(days=2), ), - TTextSeqSet( - "{[A@2000-01-01, B@2000-01-02], [C@2000-01-05]}" - ), + TTextSeqSet("{[A@2000-01-01, B@2000-01-02], [C@2000-01-05]}"), ), ], ids=["No Gaps", "With Gaps"],