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

Binary operations take the name of the left feature #415

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions temporian/core/event_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def __ne__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a != b
>>> c
indexes: []
features: [('ne_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'ne_f1_f2': [ True False True]
'f1': [ True False True]
...

```
Expand Down Expand Up @@ -193,12 +193,12 @@ def __add__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a + b
>>> c
indexes: []
features: [('add_f1_f3', int64), ('add_f2_f4', int64)]
features: [('f1', int64), ('f2', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'add_f1_f3': [ -1 101 202]
'add_f2_f4': [ 11 -11 10]
'f1': [ -1 101 202]
'f2': [ 11 -11 10]
...

```
Expand Down Expand Up @@ -245,11 +245,11 @@ def __add__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a["f1"].cast(tp.float64) + a["f2"]
>>> c
indexes: []
features: [('add_f1_f2', float64)]
features: [('f1', float64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'add_f1_f2': [ 10. 90. 205.]
'f1': [ 10. 90. 205.]
...

```
Expand All @@ -275,11 +275,11 @@ def __add__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a.resample(b) + b
>>> c
indexes: []
features: [('add_fa_fb', int64)]
features: [('fa', int64)]
events:
(4 events):
timestamps: [-1. 1.5 3. 5. ]
'add_fa_fb': [-10 16 33 53]
'fa': [-10 16 33 53]
...

```
Expand Down Expand Up @@ -314,14 +314,14 @@ def __add__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a + b.resample(a)
>>> c
indexes: [('cat', int64)]
features: [('add_M_N', int64)]
features: [('M', int64)]
events:
cat=1 (2 events):
timestamps: [1. 2.]
'add_M_N': [20 40]
'M': [20 40]
cat=2 (2 events):
timestamps: [3. 4.]
'add_M_N': [60 80]
'M': [60 80]
...

```
Expand Down Expand Up @@ -382,11 +382,11 @@ def __sub__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a - b
>>> c
indexes: []
features: [('sub_f1_f2', int64)]
features: [('f1', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'sub_f1_f2': [-10 80 205]
'f1': [-10 80 205]
...

```
Expand Down Expand Up @@ -475,11 +475,11 @@ def __mul__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a * b
>>> c
indexes: []
features: [('mult_f1_f2', int64)]
features: [('f1', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'mult_f1_f2': [ 0 300 400]
'f1': [ 0 300 400]
...

```
Expand Down Expand Up @@ -634,11 +634,11 @@ def __truediv__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a / b
>>> c
indexes: []
features: [('div_f1_f2', float64)]
features: [('f1', float64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'div_f1_f2': [0. 5. 4.]
'f1': [0. 5. 4.]
...

```
Expand All @@ -665,11 +665,11 @@ def __truediv__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a.cast(tp.float64) / b.cast(tp.float64)
>>> c
indexes: []
features: [('div_f1_f2', float64)]
features: [('f1', float64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'div_f1_f2': [0. 5. 4.]
'f1': [0. 5. 4.]
...

```
Expand Down Expand Up @@ -757,11 +757,11 @@ def __floordiv__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a // b
>>> c
indexes: []
features: [('floordiv_f1_f2', int64)]
features: [('f1', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'floordiv_f1_f2': [ 0 33 1]
'f1': [ 0 33 1]
...

```
Expand Down Expand Up @@ -850,11 +850,11 @@ def __pow__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a ** b
>>> c
indexes: []
features: [('pow_f1_f2', int64)]
features: [('f1', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'pow_f1_f2': [ 1 8 16]
'f1': [ 1 8 16]
...

```
Expand Down Expand Up @@ -943,11 +943,11 @@ def __mod__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a % b
>>> c
indexes: []
features: [('mod_f1_f2', int64)]
features: [('f1', int64)]
events:
(3 events):
timestamps: [1. 2. 3.]
'mod_f1_f2': [ 0 2 50]
'f1': [ 0 2 50]
...

```
Expand Down Expand Up @@ -1033,11 +1033,11 @@ def __gt__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a > b
>>> c
indexes: []
features: [('gt_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'gt_f1_f2': [ True False True]
'f1': [ True False True]
...

```
Expand Down Expand Up @@ -1109,11 +1109,11 @@ def __ge__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a >= b
>>> c
indexes: []
features: [('ge_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'ge_f1_f2': [ True True True]
'f1': [ True True True]
...

```
Expand Down Expand Up @@ -1185,11 +1185,11 @@ def __lt__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a < b
>>> c
indexes: []
features: [('lt_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'lt_f1_f2': [False False False]
'f1': [False False False]
...

```
Expand Down Expand Up @@ -1261,11 +1261,11 @@ def __le__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a <= b
>>> c
indexes: []
features: [('le_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'le_f1_f2': [False True False]
'f1': [False True False]
...

```
Expand Down Expand Up @@ -1336,11 +1336,11 @@ def __and__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> d = b & c
>>> d
indexes: []
features: [('and_f1_f1', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'and_f1_f1': [False True False]
'f1': [False True False]
...

```
Expand All @@ -1355,11 +1355,11 @@ def __and__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = b["f1"] & b["f2"]
>>> c
indexes: []
features: [('and_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'and_f1_f2': [False True False]
'f1': [False True False]
...

```
Expand Down Expand Up @@ -1401,11 +1401,11 @@ def __or__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> d = b | c
>>> d
indexes: []
features: [('or_f1_f1', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'or_f1_f1': [ True False True]
'f1': [ True False True]
...

```
Expand Down Expand Up @@ -1447,11 +1447,11 @@ def __xor__(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> d = b ^ c
>>> d
indexes: []
features: [('xor_f1_f1', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'xor_f1_f1': [ True False True]
'f1': [ True False True]
...

```
Expand Down Expand Up @@ -2477,11 +2477,11 @@ def equal(self: EventSetOrNode, other: Any) -> EventSetOrNode:
>>> c = a.equal(b)
>>> c
indexes: []
features: [('eq_f1_f2', bool_)]
features: [('f1', bool_)]
events:
(3 events):
timestamps: [1. 2. 3.]
'eq_f1_f2': [False True False]
'f1': [False True False]
...

```
Expand Down Expand Up @@ -3529,14 +3529,14 @@ def propagate(
>>> div = products / store_resample
>>> div
indexes: [('product', int64)]
features: [('div_sales_sales', float64)]
features: [('sales', float64)]
events:
product=1 (3 events):
timestamps: [1. 2. 3.]
'div_sales_sales': [0.01 0.01 0.0167]
'sales': [0.01 0.01 0.0167]
product=2 (3 events):
timestamps: [1. 2. 3.]
'div_sales_sales': [0.1 0.1 0.1667]
'sales': [0.1 0.1 0.1667]
...

```
Expand Down
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
8 changes: 4 additions & 4 deletions temporian/core/operators/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def glue(
>>> c = a["M"] - a["N"]

# Glue all features from a,b,c
>>> d = tp.glue(a, b, c)
>>> d = tp.glue(a, b.rename("plus_N"), c.rename("minus_N"))
>>> d
indexes: []
features: [('M', int64), ('N', int64), ('add_M_N', int64), ('sub_M_N', int64)]
features: [('M', int64), ('N', int64), ('plus_N', int64), ('minus_N', int64)]
events:
(3 events):
timestamps: [0. 1. 5.]
'M': [ 0 10 50]
'N': [ 50 100 500]
'add_M_N': [ 50 110 550]
'sub_M_N': [ -50 -90 -450]
'plus_N': [ 50 110 550]
'minus_N': [ -50 -90 -450]
...

```
Expand Down
Loading
Loading