From b187484bf0fb8a1bcad541b1238be80e7cce1d4e Mon Sep 17 00:00:00 2001 From: Chingis Oinar Date: Sat, 5 Oct 2024 00:01:16 +0900 Subject: [PATCH] refactor: remove redundant method --- feature_fabrica/transform/math.py | 7 ++++--- feature_fabrica/transform/string.py | 8 +------- tests/test_string_transform.py | 5 ----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/feature_fabrica/transform/math.py b/feature_fabrica/transform/math.py index 08bc3a5..8e600d7 100644 --- a/feature_fabrica/transform/math.py +++ b/feature_fabrica/transform/math.py @@ -13,7 +13,7 @@ class BaseReduce(Transformation): ufunc = None @beartype - def __init__(self, iterable: Iterable | None = None, expects_data: bool = True, axis: int = 0): + def __init__(self, iterable: Iterable | None = None, expects_data: bool = False, axis: int = 0): super().__init__() assert iterable or expects_data, "Either expect_data or iterable should be set!" @@ -23,9 +23,10 @@ def __init__(self, iterable: Iterable | None = None, expects_data: bool = True, self.execute = self.default # type: ignore elif expects_data and not self.iterable: self.execute = self.with_data # type: ignore[method-assign] - + elif expects_data and self.iterable: + raise ValueError("expect_data and iterable can't be set at the same time!") @beartype - def execute(self) -> NumericArray | NumericValue: + def default(self) -> NumericArray | NumericValue: if self.ufunc is None: raise NotImplementedError() iterable: NumericArray = broadcast_and_normalize_numeric_array(self.iterable) diff --git a/feature_fabrica/transform/string.py b/feature_fabrica/transform/string.py index 2052109..a117c79 100644 --- a/feature_fabrica/transform/string.py +++ b/feature_fabrica/transform/string.py @@ -35,7 +35,7 @@ def __init__(self, iterable: Iterable | None = None, expects_data: bool = False, elif expects_data and not self.iterable: self.execute = self.with_data # type: ignore[method-assign] elif expects_data and self.iterable: - self.execute = self.with_data_and_iterable # type: ignore[method-assign] + raise ValueError("expect_data and iterable can't be set at the same time!") @beartype def default(self) -> StrArray: @@ -48,12 +48,6 @@ def with_data(self, data: StrArray | list[StrArray]) -> StrArray: else: return np.array([reduce(np.char.add, arr) for arr in data], dtype=str) - @beartype - def with_data_and_iterable(self, data: StrArray) -> StrArray: - # TODO: make the order configurable? - iterable_with_data = [data] + self.iterable # type: ignore[operator] - return reduce(np.char.add, iterable_with_data) - class Strip(Transformation): _name_ = "strip" def __init__(self, chars: str | None = None): diff --git a/tests/test_string_transform.py b/tests/test_string_transform.py index 77098d6..c21455c 100644 --- a/tests/test_string_transform.py +++ b/tests/test_string_transform.py @@ -34,11 +34,6 @@ def test_concatenate_reduce(self): expected = np.array(['hello there!', 'goodbye now']) assert_array_equal(result, expected) - transform = ConcatenateReduce(iterable=[array2, array3], expects_data=True) - result = transform.execute(array1) - expected = np.array(['hello there!', 'goodbye now']) - assert_array_equal(result, expected) - stacked = np.stack([array1, array2, array3], axis=1) transform = ConcatenateReduce(expects_data=True) result = transform.execute(stacked)