def test_weighted_quantile_call( self, mocker, values, quantiles, sample_weight, expected_quantiles ): """Test the call to weighted_quantile, inlcuding the filtering out of None values.""" x = CappingTransformer(quantiles={"a": [0.1, 1], "b": [0.5, None]}) mocked = mocker.patch("tubular.capping.CappingTransformer.weighted_quantile") x.prepare_quantiles(values, quantiles, sample_weight) assert ( mocked.call_count == 1 ), f"unexpected number of calls to weighted_quantile, expecting 1 but got {mocked.call_count}" call_args = mocked.call_args_list[0] call_pos_args = call_args[0] call_kwargs = call_args[1] expected_pos_args = (values, expected_quantiles, sample_weight) assert ( call_pos_args == expected_pos_args ), f"unexpected positional args in call to weighted_quantile, expecting {expected_pos_args} but got {call_pos_args}" assert ( call_kwargs == {} ), f"unexpected kwargs in call to weighted_quantile, expecting None but got {call_kwargs}"
def test_output_from_weighted_quantile_returned( self, mocker, values, quantiles, sample_weight, expected_results ): """Test the output from weighted_quantile is returned from the function, inlcuding None values added back in.""" x = CappingTransformer(quantiles={"a": [0.1, 1], "b": [0.5, None]}) mocker.patch( "tubular.capping.CappingTransformer.weighted_quantile", return_value=["aaaa"], ) results = x.prepare_quantiles(values, quantiles, sample_weight) assert ( results == expected_results ), f"unexpected value returned from prepare_quantiles, expecting {results} but got {expected_results}"