Skip to content

Commit

Permalink
Merge pull request #311 from lvgig/292-bug-capping-transformer-get_pa…
Browse files Browse the repository at this point in the history
…rams-method-error

🐛 fixed bug with get_params method when capping_values=None
  • Loading branch information
davidhopkinson26 authored Oct 8, 2024
2 parents c3657f3 + f91fe00 commit 04c54e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Changed
- Refactored DateDifferenceTransformer tests in new format. Had to turn off autodefine new_column_name functionality to match generic test expectations. Suggest we look to turn back on in the future. `#296 https://github.com/lvgig/tubular/issues/296`
- Refactored DateDiffLeapYearTransformer tests in new format. As part of this had to remove the autodefined new_column_name, as this conflicts with the generic testing. Suggest we look to turn back on in future. `#295 https://github.com/lvgig/tubular/issues/295`
- Edited base testing setup for dates file, created new BaseDatetimeTransformer class
- fixed a bug in CappingTransformer which was preventing use of .get_params method `#311 <https://github.com/lvgig/tubular/issues/311>`_


1.3.1 (2024-07-18)
Expand Down
17 changes: 17 additions & 0 deletions tests/capping/test_CappingTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,20 @@ class TestOtherBaseBehaviour(OtherBaseBehaviourTests):
@classmethod
def setup_class(cls):
cls.transformer_name = "CappingTransformer"

def test_get_params_call_with_capping_values_none(
self,
uninitialized_transformers,
minimal_attribute_dict,
):
"""Test get_params method when capping_values is None."""
args = minimal_attribute_dict[self.transformer_name]
args["capping_values"] = None
args["quantiles"] = {"a": [0.1, 0.9]}
transformer = uninitialized_transformers[self.transformer_name](**args)

# Ensure no AttributeError is raised when calling get_params method
try:
transformer.get_params()
except AttributeError as e:
pytest.fail(f"AttributeError was raised: {e}")
3 changes: 1 addition & 2 deletions tubular/capping.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def __init__(
if capping_values is not None:
self.check_capping_values_dict(capping_values, "capping_values")

self.capping_values = capping_values

super().__init__(columns=list(capping_values.keys()), **kwargs)

if quantiles is not None:
Expand All @@ -98,6 +96,7 @@ def __init__(
super().__init__(columns=list(quantiles.keys()), **kwargs)

self.quantiles = quantiles
self.capping_values = capping_values
WeightColumnMixin.check_and_set_weight(self, weights_column)

def check_capping_values_dict(
Expand Down

0 comments on commit 04c54e9

Please sign in to comment.