Skip to content

Commit

Permalink
refactor: remove redundant method
Browse files Browse the repository at this point in the history
  • Loading branch information
cowana-ai committed Oct 4, 2024
1 parent 4dbbd76 commit b187484
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
7 changes: 4 additions & 3 deletions feature_fabrica/transform/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand All @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions feature_fabrica/transform/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions tests/test_string_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b187484

Please sign in to comment.