Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure tests: resample, lag, leak, filter, prefix, glue, where, until_next #294

Merged
merged 11 commits into from
Oct 31, 2023
289 changes: 124 additions & 165 deletions poetry.lock

Large diffs are not rendered by default.

86 changes: 81 additions & 5 deletions temporian/core/operators/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,50 @@ py_test(
],
)

py_test(
name = "test_filter",
srcs = ["test_filter.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_glue",
srcs = ["test_glue.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_lag",
srcs = ["test_lag.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_leak",
srcs = ["test_leak.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_map",
srcs = ["test_map.py"],
Expand All @@ -41,6 +85,17 @@ py_test(
],
)

py_test(
name = "test_prefix",
srcs = ["test_prefix.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_propagate",
srcs = ["test_propagate.py"],
Expand All @@ -63,6 +118,17 @@ py_test(
],
)

py_test(
name = "test_resample",
srcs = ["test_resample.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

py_test(
name = "test_select",
srcs = ["test_select.py"],
Expand All @@ -86,14 +152,13 @@ py_test(
)

py_test(
name = "until_next_test",
srcs = ["until_next_test.py"],
name = "test_until_next",
srcs = ["test_until_next.py"],
srcs_version = "PY3",
deps = [
# already_there/absl/testing:absltest
"//temporian/core/data:dtype",
"//temporian/core/data:node",
"//temporian/core/operators:until_next",
"//temporian/implementation/numpy/data:io",
"//temporian/test:utils",
],
)

Expand All @@ -119,3 +184,14 @@ py_test(
"//temporian/test:utils",
],
)

py_test(
name = "test_where",
srcs = ["test_where.py"],
srcs_version = "PY3",
deps = [
"//temporian/implementation/numpy/data:io",
# "//temporian/core/data:duration",
"//temporian/test:utils",
],
)
44 changes: 44 additions & 0 deletions temporian/core/operators/test/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from absl.testing import absltest
from absl.testing.parameterized import TestCase

from temporian.implementation.numpy.data.io import event_set
from temporian.test.utils import assertOperatorResult


class FilterTest(TestCase):
def test_basic(self):
evset = event_set(
timestamps=[1, 2, 3], features={"x": [4, 5, 6], "y": [7, 8, 9]}
)
condition = event_set(
timestamps=[1, 2, 3],
features={"c": [True, True, False]},
same_sampling_as=evset,
)

result = evset.filter(condition)

expected = event_set(
timestamps=[1, 2],
features={"x": [4, 5], "y": [7, 8]},
)

assertOperatorResult(self, result, expected, check_sampling=False)


if __name__ == "__main__":
absltest.main()
157 changes: 157 additions & 0 deletions temporian/core/operators/test/test_glue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from absl.testing import absltest
from absl.testing.parameterized import TestCase
from temporian.core.operators.glue import glue

from temporian.implementation.numpy.data.io import event_set
from temporian.test.utils import assertOperatorResult, f32


class GlueTest(TestCase):
def test_basic(self):
timestamps = [1, 1, 2, 3, 4]

evset_1 = event_set(
timestamps=timestamps,
features={
"x": ["a", "a", "a", "a", "b"],
"f1": [10, 11, 12, 13, 14],
},
indexes=["x"],
)
evset_2 = event_set(
timestamps=timestamps,
features={
"x": ["a", "a", "a", "a", "b"],
"f2": [20, 21, 22, 23, 24],
"f3": [30, 31, 32, 33, 34],
},
indexes=["x"],
same_sampling_as=evset_1,
)
evset_3 = event_set(
timestamps=timestamps,
features={
"x": ["a", "a", "a", "a", "b"],
"f4": [40, 41, 42, 43, 44],
},
indexes=["x"],
same_sampling_as=evset_1,
)

result = glue(evset_1, evset_2, evset_3)

expected = event_set(
timestamps=timestamps,
features={
"x": ["a", "a", "a", "a", "b"],
"f1": [10, 11, 12, 13, 14],
"f2": [20, 21, 22, 23, 24],
"f3": [30, 31, 32, 33, 34],
"f4": [40, 41, 42, 43, 44],
},
indexes=["x"],
same_sampling_as=evset_1,
)

assertOperatorResult(self, result, expected)

def test_non_matching_sampling(self):
with self.assertRaisesRegex(
ValueError,
"Arguments should have the same sampling.",
):
evset_1 = event_set([])
evset_2 = event_set([0])
glue(evset_1, evset_2)

def test_duplicate_feature(self):
with self.assertRaisesRegex(
ValueError,
'Feature "a" is defined in multiple input EventSetNodes',
):
evset_1 = event_set([], features={"a": []})
evset_2 = event_set(
[], features={"a": []}, same_sampling_as=evset_1
)
glue(evset_1, evset_2)

def test_order_unchanged(self):
"""Tests that input evsets' order is kept.

Regression test for failing case where glue misordered its inputs when
more than 10, because of sorted() being called over a list where
"input_10" was interpreted as less than "input_2".
"""
evset_0 = event_set(
timestamps=[1],
features={"f0": [1]},
)
evset_1 = evset_0.rename("f1")
evset_2 = evset_0.rename("f2")
evset_3 = evset_0.rename("f3")
evset_4 = evset_0.rename("f4")
evset_5 = evset_0.rename("f5")
evset_6 = evset_0.rename("f6")
evset_7 = evset_0.rename("f7")
evset_8 = evset_0.rename("f8")

# Test that alphabetical order is not used
evset_9 = evset_0.rename("a")

evset_10 = event_set(
timestamps=[1],
features={"f10": f32([1])},
same_sampling_as=evset_0,
)

result = glue(
evset_0,
evset_1,
evset_2,
evset_3,
evset_4,
evset_5,
evset_6,
evset_7,
evset_8,
evset_9,
evset_10,
)

expected = event_set(
[1],
features={
"f0": [1],
"f1": [1],
"f2": [1],
"f3": [1],
"f4": [1],
"f5": [1],
"f6": [1],
"f7": [1],
"f8": [1],
"a": [1],
"f10": f32([1]),
},
same_sampling_as=evset_0,
)

assertOperatorResult(self, result, expected)


if __name__ == "__main__":
absltest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@
# limitations under the License.

from absl.testing import absltest
from absl.testing.parameterized import TestCase

from temporian.core.operators.lag import LagOperator
from temporian.implementation.numpy.operators.lag import LagNumpyImplementation
from temporian.implementation.numpy.data.io import event_set
from temporian.implementation.numpy.operators.test.utils import (
assertEqualEventSet,
testOperatorAndImp,
)
from temporian.test.utils import assertOperatorResult


class LagNumpyImplementationTest(absltest.TestCase):
def test_base(self) -> None:
input_data = event_set(
class LagTest(TestCase):
def test_basic(self):
evset = event_set(
timestamps=[1, 2, 3, 4],
features={"x": [4, 5, 6, 7], "y": [1, 1, 2, 2]},
indexes=["y"],
)
expected_result = event_set(

result = evset.lag(2)

expected = event_set(
timestamps=[1 + 2, 2 + 2, 3 + 2, 4 + 2],
features={"x": [4, 5, 6, 7], "y": [1, 1, 2, 2]},
indexes=["y"],
)
op = LagOperator(input=input_data.node(), duration=2)
imp = LagNumpyImplementation(op)
testOperatorAndImp(self, op, imp)
filtered_evset = imp.call(input=input_data)["output"]
assertEqualEventSet(self, filtered_evset, expected_result)

assertOperatorResult(self, result, expected, check_sampling=False)


if __name__ == "__main__":
Expand Down
Loading