Skip to content

Commit

Permalink
private attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Aug 8, 2023
1 parent ae71f99 commit ddd7925
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions rdt/transformers/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def __init__(self, prefix=None, starting_value=0, suffix=None):
self.prefix = prefix
self.starting_value = starting_value
self.suffix = suffix
self.counter = 0
self._counter = 0
self.output_properties = {None: {'next_transformer': None}}

def reset_sampling(self):
"""Reset the sampling counter."""
self.counter = 0
"""Reset the sampling _counter."""
self._counter = 0

def _fit(self, data):
pass
Expand All @@ -52,11 +52,11 @@ def _reverse_transform(self, data):
Returns:
pd.Series
"""
start = self.starting_value + self.counter
start = self.starting_value + self._counter
prefix_str = self.prefix if self.prefix is not None else ''
suffix_str = self.suffix if self.suffix is not None else ''

values = [f'{prefix_str}{start + idx}{suffix_str}' for idx in range(len(data))]
self.counter += len(data)
self._counter += len(data)

return pd.Series(values)
20 changes: 10 additions & 10 deletions tests/unit/transformers/test_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test___init__default(self):
assert transformer.prefix is None
assert transformer.starting_value == 0
assert transformer.suffix is None
assert transformer.counter == 0
assert transformer._counter == 0
assert transformer.output_properties == {None: {'next_transformer': None}}

def test___init__with_parameters(self):
Expand All @@ -30,38 +30,38 @@ def test___init__with_parameters(self):
assert transformer_prefix.prefix == 'prefix_'
assert transformer_prefix.starting_value == 0
assert transformer_prefix.suffix is None
assert transformer_prefix.counter == 0
assert transformer_prefix._counter == 0
assert transformer_prefix.output_properties == {None: {'next_transformer': None}}

assert transformer_suffix.prefix is None
assert transformer_suffix.starting_value == 0
assert transformer_suffix.suffix == '_suffix'
assert transformer_suffix.counter == 0
assert transformer_suffix._counter == 0
assert transformer_suffix.output_properties == {None: {'next_transformer': None}}

assert transformer_starting_value.prefix is None
assert transformer_starting_value.starting_value == 10
assert transformer_starting_value.suffix is None
assert transformer_starting_value.counter == 0
assert transformer_starting_value._counter == 0
assert transformer_starting_value.output_properties == {None: {'next_transformer': None}}

assert transformer_all.prefix == 'prefix_'
assert transformer_all.starting_value == 10
assert transformer_all.suffix == '_suffix'
assert transformer_all.counter == 0
assert transformer_all._counter == 0
assert transformer_all.output_properties == {None: {'next_transformer': None}}

def test_reset_sampling(self):
"""Test the ``reset_sampling`` method."""
# Setup
transformer = IDGenerator()
transformer.counter = 10
transformer._counter = 10

# Run
transformer.reset_sampling()

# Assert
assert transformer.counter == 0
assert transformer._counter == 0

def test__fit(self):
"""Test the ``_fit`` method."""
Expand Down Expand Up @@ -89,15 +89,15 @@ def test__reverse_transform(self):
"""Test the ``_reverse_transform`` method."""
# Setup
transformer = IDGenerator()
transformer.counter = 10
transformer._counter = 10

# Run
result = transformer._reverse_transform(np.array([1, 2, 3]))

# Assert
assert isinstance(result, pd.Series)
assert result.tolist() == ['10', '11', '12']
assert transformer.counter == 13
assert transformer._counter == 13

def test__reverse_transform_with_everything(self):
"""Test the ``_reverse_transform`` method with all parameters."""
Expand All @@ -110,4 +110,4 @@ def test__reverse_transform_with_everything(self):
# Assert
assert isinstance(result, pd.Series)
assert result.tolist() == ['prefix_100_suffix', 'prefix_101_suffix', 'prefix_102_suffix']
assert transformer.counter == 3
assert transformer._counter == 3

0 comments on commit ddd7925

Please sign in to comment.