Skip to content

Commit

Permalink
Binary operations take the name of the left feature
Browse files Browse the repository at this point in the history
  • Loading branch information
javiber committed Apr 8, 2024
1 parent ce03dca commit 0c9085b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
7 changes: 1 addition & 6 deletions temporian/core/operators/binary/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
# outputs
output_features = [ # pylint: disable=g-complex-comprehension
FeatureSchema(
name=self.output_feature_name(feature_1, feature_2),
name=feature_1.name,
dtype=self.output_feature_dtype(feature_1, feature_2),
)
for feature_1, feature_2 in zip(
Expand Down Expand Up @@ -107,11 +107,6 @@ def operator_def_key(cls) -> str:
def prefix(self) -> str:
"""Gets the prefix to use for the output features."""

def output_feature_name(
self, feature_1: FeatureSchema, feature_2: FeatureSchema
) -> str:
return f"{self.prefix}_{feature_1.name}_{feature_2.name}"

def output_feature_dtype(
self, feature_1: FeatureSchema, feature_2: FeatureSchema
) -> DType:
Expand Down
26 changes: 12 additions & 14 deletions temporian/core/operators/test/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_addition(self) -> None:
features={
"store_id": [1, 1, 1, 1, 2, 2, 2, 2],
"product_id": [1, 1, 1, 2, 2, 2, 3, 3],
"add_f1_f3": f64([-9.5, 9.5, 32, 10, 3, 0, 6, 9]),
"add_f2_f4": f32([6, 5, 4, 6, -3, 8, 11, 11]),
"f1": f64([-9.5, 9.5, 32, 10, 3, 0, 6, 9]),
"f2": f32([6, 5, 4, 6, -3, 8, 11, 11]),
},
indexes=["store_id", "product_id"],
same_sampling_as=self.evset_1,
Expand All @@ -71,8 +71,8 @@ def test_subtraction(self) -> None:
features={
"store_id": [1, 1, 1, 1, 2, 2, 2, 2],
"product_id": [1, 1, 1, 2, 2, 2, 3, 3],
"sub_f1_f3": f64([-18.5, 20.5, 0, 10, -3, 16, 0, -1]),
"sub_f2_f4": f32([-4, -1, 2, 2, 13, 4, 3, 5]),
"f1": f64([-18.5, 20.5, 0, 10, -3, 16, 0, -1]),
"f2": f32([-4, -1, 2, 2, 13, 4, 3, 5]),
},
indexes=["store_id", "product_id"],
same_sampling_as=self.evset_1,
Expand All @@ -85,8 +85,8 @@ def test_multiplication(self) -> None:
features={
"store_id": [1, 1, 1, 1, 2, 2, 2, 2],
"product_id": [1, 1, 1, 2, 2, 2, 3, 3],
"mult_f1_f3": f64([-63, -82.5, 256, 0, 0, -64, 9, 20]),
"mult_f2_f4": f32([5, 6, 3, 8, -40, 12, 28, 24]),
"f1": f64([-63, -82.5, 256, 0, 0, -64, 9, 20]),
"f2": f32([5, 6, 3, 8, -40, 12, 28, 24]),
},
indexes=["store_id", "product_id"],
same_sampling_as=self.evset_1,
Expand All @@ -99,10 +99,8 @@ def test_division(self) -> None:
features={
"store_id": [1, 1, 1, 1, 2, 2, 2, 2],
"product_id": [1, 1, 1, 2, 2, 2, 3, 3],
"div_f1_f3": f64(
[-14 / 4.5, -15 / 5.5, 1, np.inf, 0, -1, 1, 0.8]
),
"div_f2_f4": f32([0.2, 2 / 3, 3, 2, -0.625, 3, 1.75, 8 / 3]),
"f1": f64([-14 / 4.5, -15 / 5.5, 1, np.inf, 0, -1, 1, 0.8]),
"f2": f32([0.2, 2 / 3, 3, 2, -0.625, 3, 1.75, 8 / 3]),
},
indexes=["store_id", "product_id"],
same_sampling_as=self.evset_1,
Expand All @@ -115,8 +113,8 @@ def test_floordiv(self) -> None:
features={
"store_id": [1, 1, 1, 1, 2, 2, 2, 2],
"product_id": [1, 1, 1, 2, 2, 2, 3, 3],
"floordiv_f1_f3": f64([-4, -3, 1, np.inf, 0, -1, 1, 0]),
"floordiv_f2_f4": f32([0, 0, 3, 2, -1, 3, 1, 2]),
"f1": f64([-4, -3, 1, np.inf, 0, -1, 1, 0]),
"f2": f32([0, 0, 3, 2, -1, 3, 1, 2]),
},
indexes=["store_id", "product_id"],
same_sampling_as=self.evset_1,
Expand All @@ -142,8 +140,8 @@ def test_noindex_unsorted(self) -> None:
expected = event_set(
timestamps=[0, 1, 2, 3],
features={
"add_f1_f2": [0, 11, 22, 33],
"add_f2_f1": [0, 9, 18, 27],
"f1": [0, 11, 22, 33],
"f2": [0, 9, 18, 27],
},
same_sampling_as=evset_1,
)
Expand Down

0 comments on commit 0c9085b

Please sign in to comment.