-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: temporian.EventSet.drop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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. | ||
|
||
|
||
"""Drop operator class and public API function definitions.""" | ||
|
||
from typing import List | ||
from temporian.core import operator_lib | ||
from temporian.core.compilation import compile | ||
from temporian.core.data.node import ( | ||
EventSetNode, | ||
create_node_new_features_new_sampling, | ||
) | ||
from temporian.core.operators.base import Operator | ||
from temporian.core.typing import EventSetOrNode | ||
from temporian.proto import core_pb2 as pb | ||
from temporian.utils.typecheck import typecheck | ||
from temporian.core.operators.select import select | ||
|
||
|
||
@typecheck | ||
@compile | ||
def drop( | ||
input: EventSetOrNode, feature_names: str | List[str] | ||
) -> EventSetOrNode: | ||
assert isinstance(input, EventSetNode) | ||
|
||
if isinstance(feature_names, str): | ||
feature_names = [feature_names] | ||
|
||
input_features = input.schema.feature_names() | ||
|
||
if not all([fn in input_features for fn in feature_names]): | ||
raise TypeError( | ||
"Features" | ||
f" {[fn for fn in feature_names if fn not in input_features]} are" | ||
" not present in the input features" | ||
) | ||
|
||
return select( | ||
input=input, | ||
feature_names=[fn for fn in input_features if fn not in feature_names], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 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, parameterized | ||
|
||
from temporian.implementation.numpy.data.io import event_set | ||
from temporian.test.utils import assertOperatorResult | ||
|
||
|
||
class DropTest(parameterized.TestCase): | ||
def test_drop_str(self): | ||
evset = event_set( | ||
timestamps=[1, 2, 3], | ||
features={ | ||
"a": [1.0, 2.0, 3.0], | ||
"b": [5, 6, 7], | ||
"c": ["A", "A", "B"], | ||
}, | ||
indexes=["c"], | ||
) | ||
result = evset.drop("a") | ||
|
||
expected = event_set( | ||
timestamps=[1, 2, 3], | ||
features={ | ||
"b": [5, 6, 7], | ||
"c": ["A", "A", "B"], | ||
}, | ||
indexes=["c"], | ||
same_sampling_as=evset, | ||
) | ||
|
||
assertOperatorResult(self, result, expected) | ||
|
||
def test_drop_list(self): | ||
evset = event_set( | ||
timestamps=[1, 2, 3], | ||
features={ | ||
"a": [1.0, 2.0, 3.0], | ||
"b": [5, 6, 7], | ||
"c": ["A", "A", "B"], | ||
}, | ||
indexes=["c"], | ||
) | ||
result = evset.drop(["a", "b"]) | ||
|
||
expected = event_set( | ||
timestamps=[1, 2, 3], | ||
features={ | ||
"c": ["A", "A", "B"], | ||
}, | ||
indexes=["c"], | ||
same_sampling_as=evset, | ||
) | ||
|
||
assertOperatorResult(self, result, expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
absltest.main() |